AI CSS Animations

Pulsing Gradient Border

A gradient ring swells outward and thins again like slow breathing while its colors turn. The width is a registered @property length on a masked layer, so the box itself never changes size.

Also known as: pulsating border css, breathing border animation, pulse border effect css.

Pulsing border

HTML

<div class="bdr-pulsing-gradient-border">Pulsing border</div>

CSS

@property --bdr-pulsing-gradient-border-w {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;
}
@property --bdr-pulsing-gradient-border-a {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}
.bdr-pulsing-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;
  background: color-mix(in srgb, var(--c) 10%, #0b0f19);
  color: #f1f5f9;
}
.bdr-pulsing-gradient-border::before {
  content: "";
  position: absolute;
  inset: calc(var(--bdr-pulsing-gradient-border-w) * -1);
  padding: var(--bdr-pulsing-gradient-border-w);
  border-radius: calc(1em + var(--bdr-pulsing-gradient-border-w));
  background: conic-gradient(from var(--bdr-pulsing-gradient-border-a), var(--c), color-mix(in oklch, var(--c), #ec4899 75%), color-mix(in oklch, var(--c), #8b5cf6 60%), var(--c));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  pointer-events: none;
  animation:
    bdr-pulsing-gradient-border-breathe 2.4s cubic-bezier(0.45, 0, 0.55, 1) infinite,
    bdr-pulsing-gradient-border-turn 9.6s linear infinite;
}
@keyframes bdr-pulsing-gradient-border-breathe {
  0%, 100% { --bdr-pulsing-gradient-border-w: 0.1em; opacity: 0.7; }
  50%      { --bdr-pulsing-gradient-border-w: 0.45em; opacity: 1; }
}
@keyframes bdr-pulsing-gradient-border-turn {
  to { --bdr-pulsing-gradient-border-a: 360deg; }
}

@media (prefers-reduced-motion: reduce) {
  .bdr-pulsing-gradient-border, .bdr-pulsing-gradient-border *, .bdr-pulsing-gradient-border::before, .bdr-pulsing-gradient-border::after, .bdr-pulsing-gradient-border *::before, .bdr-pulsing-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