AI CSS Animations

Aurora Border

Green, teal and violet light drifts along the inside of a dark frame like the northern lights. Two conic layers turn at different speeds under a blur, with a crisp copy masked to the rim.

Also known as: aurora gradient border, blurred gradient border css, northern lights border.

Aurora

HTML

<div class="bdr-aurora-border"><span class="bdr-aurora-border-rim"></span>Aurora</div>

CSS

@property --bdr-aurora-border-a {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}
@property --bdr-aurora-border-b {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}
.bdr-aurora-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;
  --night: color-mix(in srgb, var(--c) 8%, #050914);
  --aurora:
    conic-gradient(from var(--bdr-aurora-border-a) at 30% 50%, #34d399, transparent 18% 40%, var(--c) 55%, transparent 70% 85%, #34d399),
    conic-gradient(from var(--bdr-aurora-border-b) at 70% 50%, #a78bfa, transparent 20% 45%, #22d3ee 60%, transparent 75% 90%, #a78bfa);
  isolation: isolate;
  overflow: hidden;
  background: var(--night);
  color: #e2e8f0;
  letter-spacing: 0.04em;
  animation:
    bdr-aurora-border-a 9s linear infinite,
    bdr-aurora-border-b 13s linear infinite reverse;
}
.bdr-aurora-border::before,
.bdr-aurora-border::after {
  content: "";
  position: absolute;
  pointer-events: none;
}
.bdr-aurora-border::before {
  inset: 0;
  z-index: -2;
  background: var(--aurora);
  filter: blur(1.1em);
}
.bdr-aurora-border::after {
  inset: 1.1em 1.3em;
  z-index: -1;
  border-radius: 1em;
  background: var(--night);
  filter: blur(0.9em);
}
.bdr-aurora-border-rim {
  position: absolute;
  inset: 0;
  padding: 0.1em;
  border-radius: inherit;
  background: var(--aurora);
  -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;
}
@keyframes bdr-aurora-border-a {
  to { --bdr-aurora-border-a: 360deg; }
}
@keyframes bdr-aurora-border-b {
  to { --bdr-aurora-border-b: 360deg; }
}

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