AI CSS Animations

Spotlight Border

A lamp at the bottom of the box swings a cone of light from side to side, lighting the border wherever it lands. The conic angle eases between two limits instead of turning all the way round.

Also known as: conic spotlight border, sweeping light border, searchlight border css.

Spotlight

HTML

<div class="bdr-spotlight-border">Spotlight</div>

CSS

@property --bdr-spotlight-border-a {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}
.bdr-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;
  --beam: conic-gradient(from var(--bdr-spotlight-border-a) at 50% 100%, transparent, color-mix(in srgb, var(--c) 70%, #fff) 18deg, transparent 36deg);
  isolation: isolate;
  overflow: hidden;
  background:
    radial-gradient(1.4em 0.5em at 50% 100%, color-mix(in srgb, var(--c) 50%, #fff), transparent),
    color-mix(in srgb, var(--c) 10%, #0b0f19);
  color: #f1f5f9;
  animation: bdr-spotlight-border-sweep 3.2s cubic-bezier(0.45, 0, 0.55, 1) infinite;
}
.bdr-spotlight-border::before,
.bdr-spotlight-border::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
}
.bdr-spotlight-border::before {
  z-index: -1;
  background: var(--beam);
  opacity: 0.2;
}
.bdr-spotlight-border::after {
  padding: 0.14em;
  background: var(--beam), color-mix(in srgb, var(--c) 14%, 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);
}
@keyframes bdr-spotlight-border-sweep {
  0%, 100% { --bdr-spotlight-border-a: -62deg; }
  50%      { --bdr-spotlight-border-a: 26deg; }
}

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