Mesh gradient hero

Putcode·20 hours ago
@property --x1 { syntax: "<percentage>"; inherits: false; initial-value: 20%; }
@property --y1 { syntax: "<percentage>"; inherits: false; initial-value: 20%; }
@property --x2 { syntax: "<percentage>"; inherits: false; initial-value: 80%; }
@property --y2 { syntax: "<percentage>"; inherits: false; initial-value: 75%; }

body {
  margin: 0;
  font: 16px/1.5 system-ui, sans-serif;
}

.mesh {
  position: relative;
  isolation: isolate;
  min-height: 100vh;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(at var(--x1) var(--y1), #ff8a5c 0, transparent 45%),
    radial-gradient(at var(--x2) var(--y1), #7b61ff 0, transparent 50%),
    radial-gradient(at var(--x1) var(--y2), #2dd4bf 0, transparent 45%),
    radial-gradient(at var(--x2) var(--y2), #f9c74f 0, transparent 50%),
    #f6efe7;
  animation: drift 16s ease-in-out infinite alternate;
}

.mesh::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.5'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
}

@keyframes drift {
  to {
    --x1: 35%;
    --y1: 5%;
    --x2: 65%;
    --y2: 95%;
  }
}

.mesh__content {
  max-width: 30rem;
  padding: 2rem;
  color: #1c1a17;
  text-align: center;
}

.mesh__content h1 {
  margin: 0;
  font-size: clamp(2rem, 6vw, 3.4rem);
  line-height: 1.02;
  letter-spacing: -0.04em;
  text-wrap: balance;
}

.mesh__content p {
  margin: 0.8rem 0 1.6rem;
  color: #3d3933;
}

.mesh__form {
  display: flex;
  gap: 6px;
  padding: 6px;
  border-radius: 14px;
  background: rgb(255 255 255 / 0.55);
  backdrop-filter: blur(12px);
}

.mesh__form input {
  flex: 1;
  min-width: 0;
  padding: 0 12px;
  border: 0;
  background: transparent;
  font: inherit;
  outline: none;
}

.mesh__form button {
  padding: 0.7em 1.1em;
  border: 0;
  border-radius: 10px;
  background: #1c1a17;
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.mesh__form:focus-within {
  outline: 2px solid #1c1a17;
}

@media (prefers-reduced-motion: reduce) {
  .mesh {
    animation: none;
  }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

How to use it

The four blob positions are registered properties (--x1 to --y2), so the gradient itself animates. The grain is an inline SVG feTurbulence used as a background image. Swap the colors in .mesh.