AI CSS Animations

Roaming Spotlight Border

A soft spotlight travels the edge of a dark card, lighting the border it touches and washing the surface beside it. Two registered @property percentages walk the light around at one steady speed.

Also known as: spotlight border, spotlight border css, light sweeping border, card spotlight effect.

Preview deployments Every push gets its own URL, live in 41 seconds.

HTML

<div class="bdr-roaming-spotlight-border">
  <span class="bdr-roaming-spotlight-border-icon" aria-hidden="true"></span>
  <span class="bdr-roaming-spotlight-border-title">Preview deployments</span>
  <span class="bdr-roaming-spotlight-border-text">Every push gets its own URL, live in 41 seconds.</span>
</div>

CSS

@property --bdr-roaming-spotlight-border-x {
  syntax: "<percentage>";
  inherits: true;
  initial-value: 0%;
}
@property --bdr-roaming-spotlight-border-y {
  syntax: "<percentage>";
  inherits: true;
  initial-value: 0%;
}
.bdr-roaming-spotlight-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;
  --at: var(--bdr-roaming-spotlight-border-x) var(--bdr-roaming-spotlight-border-y);
  box-sizing: border-box;
  isolation: isolate;
  place-items: initial;
  align-content: center;
  gap: 0.35em;
  padding: 1.2em 1.3em;
  background: color-mix(in srgb, var(--c) 10%, #0b0f19);
  color: #f1f5f9;
  animation: bdr-roaming-spotlight-border-roam 7s linear infinite;
}
.bdr-roaming-spotlight-border::before,
.bdr-roaming-spotlight-border::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
}
.bdr-roaming-spotlight-border::before {
  z-index: -1;
  background: radial-gradient(9em circle at var(--at), color-mix(in srgb, var(--c) 20%, transparent), transparent 70%);
}
.bdr-roaming-spotlight-border::after {
  padding: 2px;
  background:
    radial-gradient(4.5em circle at var(--at), color-mix(in srgb, var(--c) 10%, #fff), var(--c) 35%, transparent 80%),
    color-mix(in srgb, #fff 10%, transparent);
  -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);
}
.bdr-roaming-spotlight-border-icon {
  width: 1.7em;
  height: 1.7em;
  margin-bottom: 0.35em;
  border-radius: 0.45em;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--c) 30%, #fff), var(--c));
  box-shadow: 0 0.3em 0.8em -0.2em var(--c);
}
.bdr-roaming-spotlight-border-title { font-size: 0.95em; }
.bdr-roaming-spotlight-border-text {
  font-size: 0.75em;
  font-weight: 450;
  line-height: 1.4;
  color: color-mix(in srgb, #f1f5f9 62%, transparent);
}
/* 15em by 8.5em is 47em around, so each side takes its share of the loop. */
@keyframes bdr-roaming-spotlight-border-roam {
  0%, 100% { --bdr-roaming-spotlight-border-x: 0%; --bdr-roaming-spotlight-border-y: 0%; }
  31.9%    { --bdr-roaming-spotlight-border-x: 100%; --bdr-roaming-spotlight-border-y: 0%; }
  50%      { --bdr-roaming-spotlight-border-x: 100%; --bdr-roaming-spotlight-border-y: 100%; }
  81.9%    { --bdr-roaming-spotlight-border-x: 0%; --bdr-roaming-spotlight-border-y: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .bdr-roaming-spotlight-border {
    animation: none;
    --bdr-roaming-spotlight-border-x: 85%;
    --bdr-roaming-spotlight-border-y: 0%;
  }
}

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