AI CSS Animations

Stepped Rainbow Border

Six solid rainbow segments ring the box and tick forward one slot at a time. The conic-gradient uses hard color stops with small gaps, and each 60 degree step eases in and out on its own.

Also known as: hard stop gradient border, segmented rainbow border, rainbow segments css.

Stepped rainbow

HTML

<div class="bdr-stepped-rainbow-border">Stepped rainbow</div>

CSS

@property --bdr-stepped-rainbow-border-a {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}
.bdr-stepped-rainbow-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;
  box-sizing: border-box;
  border: 0.24em solid transparent;
  background:
    linear-gradient(#fff, #fff) padding-box,
    conic-gradient(from var(--bdr-stepped-rainbow-border-a),
      #ef4444 0 15.6%, transparent 0 16.67%,
      #f97316 0 32.3%, transparent 0 33.33%,
      #facc15 0 49%, transparent 0 50%,
      #22c55e 0 65.6%, transparent 0 66.67%,
      #3b82f6 0 82.3%, transparent 0 83.33%,
      #a855f7 0 99%, transparent 0) border-box;
  color: color-mix(in srgb, var(--c) 55%, #111827);
  animation: bdr-stepped-rainbow-border-tick 6s cubic-bezier(0.7, 0, 0.25, 1) infinite;
}
@keyframes bdr-stepped-rainbow-border-tick {
  0%      { --bdr-stepped-rainbow-border-a: 0deg; }
  16.667% { --bdr-stepped-rainbow-border-a: 60deg; }
  33.333% { --bdr-stepped-rainbow-border-a: 120deg; }
  50%     { --bdr-stepped-rainbow-border-a: 180deg; }
  66.667% { --bdr-stepped-rainbow-border-a: 240deg; }
  83.333% { --bdr-stepped-rainbow-border-a: 300deg; }
  100%    { --bdr-stepped-rainbow-border-a: 360deg; }
}

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