AI CSS Animations

Mesh Gradient Border

Soft blobs of color wander around the frame and melt into each other, like a mesh gradient in motion. Three radial gradients ride two registered @property percentages instead of rotating.

Also known as: mesh gradient border css, fluid gradient border, lava lamp border.

Mesh gradient

HTML

<div class="bdr-mesh-gradient-border">Mesh gradient</div>

CSS

@property --bdr-mesh-gradient-border-x {
  syntax: "<percentage>";
  inherits: false;
  initial-value: 0%;
}
@property --bdr-mesh-gradient-border-y {
  syntax: "<percentage>";
  inherits: false;
  initial-value: 0%;
}
.bdr-mesh-gradient-border {
  --c: var(--bdr-color, #3b82f6);
  font-size: var(--bdr-size, 16px);
  position: relative;
  display: grid;
  place-items: center;
  width: 15em;
  height: 8.5em;
  border-radius: 1em;
  font-family: system-ui, sans-serif;
  font-weight: 600;
  --x: var(--bdr-mesh-gradient-border-x);
  --y: var(--bdr-mesh-gradient-border-y);
  box-sizing: border-box;
  border: 0.26em solid transparent;
  background:
    linear-gradient(#fff, #fff) padding-box,
    radial-gradient(circle at var(--x) var(--y), color-mix(in oklch, var(--c), #ec4899 85%), transparent 55%) border-box,
    radial-gradient(circle at calc(100% - var(--x)) calc(100% - var(--y)), color-mix(in oklch, var(--c), #22d3ee 80%), transparent 55%) border-box,
    radial-gradient(circle at var(--y) calc(100% - var(--x)), color-mix(in oklch, var(--c), #facc15 85%), transparent 50%) border-box,
    linear-gradient(var(--c), var(--c)) border-box;
  color: #111827;
  animation: bdr-mesh-gradient-border-drift 8s cubic-bezier(0.45, 0, 0.55, 1) infinite;
}
@keyframes bdr-mesh-gradient-border-drift {
  0%, 100% { --bdr-mesh-gradient-border-x: 10%; --bdr-mesh-gradient-border-y: 15%; }
  25%      { --bdr-mesh-gradient-border-x: 90%; --bdr-mesh-gradient-border-y: 25%; }
  50%      { --bdr-mesh-gradient-border-x: 80%; --bdr-mesh-gradient-border-y: 90%; }
  75%      { --bdr-mesh-gradient-border-x: 15%; --bdr-mesh-gradient-border-y: 80%; }
}

@media (prefers-reduced-motion: reduce) {
  .bdr-mesh-gradient-border, .bdr-mesh-gradient-border *, .bdr-mesh-gradient-border::before, .bdr-mesh-gradient-border::after, .bdr-mesh-gradient-border *::before, .bdr-mesh-gradient-border *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --bdr-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --bdr-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 16px.
  • Speed: change the duration on the transition or animation shorthand. Staggered delays are relative, so they keep their rhythm.
  • Reduced motion: the rule at the end of the CSS turns the motion off for people who asked their OS for less of it. Keep it.

Similar border animations