AI CSS Animations

Neon Border

A neon tube framing a dark panel, with a hot white core, a colored halo and light spilling onto the wall. It hums and blinks out for a beat now and then. Only opacity animates.

Also known as: css neon border, neon border animation, neon glow border css.

Open late

HTML

<div class="bdr-neon-border"><span class="bdr-neon-border-text">Open late</span></div>

CSS

.bdr-neon-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;
  --lit: color-mix(in srgb, var(--c) 35%, #fff);
  background: color-mix(in srgb, var(--c) 7%, #0a0a10);
  box-shadow: 0 0 1.4em color-mix(in srgb, var(--c) 22%, transparent);
  color: var(--lit);
}
.bdr-neon-border::before,
.bdr-neon-border::after {
  content: "";
  position: absolute;
  pointer-events: none;
  animation: bdr-neon-border-hum 5s linear infinite;
}
.bdr-neon-border::before {
  inset: 0.6em;
  border: 0.14em solid var(--lit);
  border-radius: 0.55em;
  box-shadow:
    0 0 0.15em var(--c),
    0 0 0.6em var(--c),
    0 0 1.3em color-mix(in srgb, var(--c) 55%, transparent),
    inset 0 0 0.15em var(--c),
    inset 0 0 0.7em color-mix(in srgb, var(--c) 50%, transparent);
}
.bdr-neon-border::after {
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--c) 16%, transparent), transparent);
}
.bdr-neon-border-text {
  position: relative;
  font-size: 1.15em;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-shadow: 0 0 0.12em var(--c), 0 0 0.5em var(--c);
  animation: bdr-neon-border-hum 5s linear infinite;
}
@keyframes bdr-neon-border-hum {
  0%, 9%, 13.5%, 64%, 66%, 100% { opacity: 1; }
  10%, 12% { opacity: 0.3; }
  11%      { opacity: 0.95; }
  40%      { opacity: 0.92; }
  65%      { opacity: 0.55; }
}

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