AI CSS Animations

Radar Background

A radar screen: range rings and crosshairs, a beam sweeping around with a fading trail, and blips that flash exactly as the beam passes them. The blip delays are computed from their angles.

Also known as: radar sweep animation css, radar scanner background, sonar screen css.

HTML

<div class="bgx-radar-sweep" aria-hidden="true">
  <span class="bgx-radar-sweep-beam"></span>
  <span class="bgx-radar-sweep-blip" style="--x: 7em; --y: -3em; --d: -3.26s"></span>
  <span class="bgx-radar-sweep-blip" style="--x: -9em; --y: -4.5em; --d: -0.7s"></span>
  <span class="bgx-radar-sweep-blip" style="--x: -4em; --y: 5em; --d: -1.57s"></span>
  <span class="bgx-radar-sweep-blip" style="--x: 11em; --y: 4em; --d: -2.78s"></span>
  <span class="bgx-radar-sweep-blip" style="--x: 2em; --y: -6.2em; --d: -3.8s"></span>
</div>

CSS

.bgx-radar-sweep {
  --c: var(--bgx-color, #3b82f6);
  font-size: var(--bgx-size, 16px);
  position: absolute;
  inset: 0;
  overflow: hidden;
  --t: 4s;
  container-type: size;
  background:
    repeating-radial-gradient(circle, transparent 0 calc(3em - 1px), color-mix(in srgb, var(--c) 30%, transparent) calc(3em - 1px) 3em),
    linear-gradient(90deg, transparent calc(50% - 0.5px), color-mix(in srgb, var(--c) 35%, transparent) 0 calc(50% + 0.5px), transparent 0),
    linear-gradient(transparent calc(50% - 0.5px), color-mix(in srgb, var(--c) 35%, transparent) 0 calc(50% + 0.5px), transparent 0),
    radial-gradient(circle, color-mix(in srgb, var(--c) 20%, #03060a), color-mix(in srgb, var(--c) 5%, #020305) 75%);
}
.bgx-radar-sweep-beam {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 150cqmax;
  height: 150cqmax;
  margin: -75cqmax 0 0 -75cqmax;
  border-radius: 50%;
  background: conic-gradient(transparent 0 280deg, color-mix(in srgb, var(--c) 8%, transparent) 290deg, color-mix(in srgb, var(--c) 45%, transparent) 357deg, var(--c) 359.6deg, transparent 360deg);
  animation: bgx-radar-sweep-turn var(--t) linear infinite;
}
.bgx-radar-sweep-blip {
  position: absolute;
  top: calc(50% + var(--y));
  left: calc(50% + var(--x));
  width: 0.5em;
  height: 0.5em;
  margin: -0.25em 0 0 -0.25em;
  border-radius: 50%;
  background: color-mix(in srgb, var(--c) 45%, #fff);
  box-shadow: 0 0 0.6em var(--c);
  animation: bgx-radar-sweep-blip var(--t) ease-out var(--d) infinite;
}
@keyframes bgx-radar-sweep-turn {
  to { transform: rotate(1turn); }
}
@keyframes bgx-radar-sweep-blip {
  0%       { opacity: 1; transform: scale(1.3); }
  70%, 100% { opacity: 0; transform: scale(0.7); }
}

@media (prefers-reduced-motion: reduce) {
  .bgx-radar-sweep, .bgx-radar-sweep *, .bgx-radar-sweep::before, .bgx-radar-sweep::after, .bgx-radar-sweep *::before, .bgx-radar-sweep *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Tailwind CSS version

The same effect using Tailwind utility classes. No custom CSS or config needed.

<div class="absolute inset-0 overflow-hidden bg-[radial-gradient(circle,#0b1627,#020305_75%)]">
  <div class="absolute inset-0 bg-[repeating-radial-gradient(circle,transparent_0_47px,rgb(59_130_246/.3)_47px_48px)]"></div>
  <div class="absolute left-1/2 top-1/2 -ml-[75vmax] -mt-[75vmax] h-[150vmax] w-[150vmax] animate-spin rounded-full bg-[conic-gradient(transparent_0_280deg,rgb(59_130_246/.45)_357deg,#3b82f6_359.6deg,transparent_360deg)] [animation-duration:4s]"></div>
  <span class="absolute left-[calc(50%_+_7rem)] top-[calc(50%_-_3rem)] h-2 w-2 animate-ping rounded-full bg-blue-300 [animation-duration:4s] [animation-delay:-3.26s]"></span>
  <span class="absolute left-[calc(50%_-_9rem)] top-[calc(50%_-_4.5rem)] h-2 w-2 animate-ping rounded-full bg-blue-300 [animation-duration:4s] [animation-delay:-0.7s]"></span>
  <span class="absolute left-[calc(50%_-_4rem)] top-[calc(50%_+_5rem)] h-2 w-2 animate-ping rounded-full bg-blue-300 [animation-duration:4s] [animation-delay:-1.57s]"></span>
</div>

Customizing this snippet

  • Color: set --bgx-color on the element or a parent. Currently previewing #3b82f6.
  • Pattern scale: set --bgx-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 animated backgrounds