Open late

How it works

A neon sign from text and shadows

Real neon is a glass tube with a hot, almost white core and a colored haze around it. On a web page that is a few blurred copies of the letters in the tube color, painted behind text that stays real text: selectable, searchable and read by screen readers.

1. The glow: stacked shadows

One blurred shadow looks like a smudge, not like light. Light around a tube falls off quickly near the glass and then fades out slowly, so the sign stacks several shadows with growing radii. Here each layer has twice the radius of the one inside it, ending at Glow radius: a few layers cover everything from the tight halo to the wide haze on the wall. The radii are in em, so the glow scales with the font size.

The letters themselves are the tube color mixed towards white (Hot core), and the innermost shadow uses that same pale color: right at the glass the light is almost white, further out only the gas color is left.

text-shadow
Every shadow is painted independently from the glyph shapes, behind the text. Cheap, predictable, and it follows the text across line breaks.
drop-shadow
A chain of filter: drop-shadow() functions, the CSS shorthand for the SVG <feDropShadow> primitive. Each filter in the chain shadows the result of the previous one, glow included, so the bloom builds up and gets brighter and softer with the same numbers. It costs more: the element is rendered into an offscreen buffer and blurred once per function.
@property --on { syntax: '<number>'; inherits: false; initial-value: 1; }

.sign {
  background: #120a1c;
  font-family: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Varela Round", "Nunito", system-ui, sans-serif;
}

.sign span {
  /* --on: 1 = lit, 0 = unlit */
  --glow: color-mix(in oklab, #ff3fd2 calc(var(--on) * 100%), transparent);
  --halo: color-mix(in oklab, #ffc5f2 calc(var(--on) * 100%), transparent);
  color: color-mix(in oklab, #ffc5f2 calc(var(--on) * 100%), #ac2c92);
  text-shadow: 0 0 0.0563em var(--halo), 0 0 0.1125em var(--glow), 0 0 0.225em var(--glow), 0 0 0.45em var(--glow), 0 0 0.9em var(--glow);
}

.sign .flicker {
  --depth: 0.85;
  animation: flicker 6s step-end infinite;
}

.sign .off {
  color: #ac2c92;
  text-shadow: none;
}

@keyframes flicker {
  0% { --on: 1; }
  40% { --on: calc(1 - var(--depth) * 1); }
  41.3333% { --on: 1; }
  45% { --on: calc(1 - var(--depth) * 0.6); }
  46.3333% { --on: 1; }
  80% { --on: calc(1 - var(--depth) * 0.9); }
  82% { --on: 1; }
  100% { --on: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .sign .flicker { animation: none; }
}
<p class="sign">
  <span>Open l</span><span class="flicker">a</span><span>te</span>
</p>

2. One number drives the light

Each span has a level --on from 0 (unlit) to 1 (lit). The glow color is the tube color at --on × Intensity opacity via color-mix(), and the text color is mixed between the lit fill and an unlit color. Flicker, power-on and dead letters only change that number.

--on is registered with @property as a <number>, so it can be used inside calc() while it animates. Without the registration (older browsers, or a stylesheet inside a shadow root, where @property is ignored) the property animates discretely, flipping from one value to the next. For this animation that makes no difference: it is stepped anyway.

3. Flicker that is safe to look at

A flickering tube is the classic neon detail, and also a classic way to hurt people. Flashing content can trigger seizures in people with photosensitive epilepsy; WCAG 2.3.1 allows no more than three flashes in any one second, where a flash is a pair of opposing changes in brightness. The flicker here is designed around that:

  • It is a fixed, sparse pattern: three dips in a 6-second cycle, two of them close together like a failing starter. A unit test slides a one-second window over three cycles back to back and counts every level change as half a flash, even tiny ones (the guideline only counts big changes). The worst second has 2.
  • The keyframes use animation-timing-function: step-end, so the level jumps like a tube that strikes or doesn't. That also means the shadows only repaint at the jumps, not on every frame.
  • Power-on (1.2s, once) is checked together with the flicker, so the two can't add up to more than the limit either.
  • Under prefers-reduced-motion: reduce both animations are off and the sign is simply lit. The pause button stops them with animation-play-state.
  • By default one letter flickers. A whole sign that dips is a much bigger area changing brightness; keep the depth low if you flicker everything.
@property --power { syntax: '<number>'; inherits: true; initial-value: 1; }

.sign { animation: power 1.2s step-end both; }
/* each span then uses calc(var(--power) * var(--on)) instead of var(--on) */

@keyframes power {
  0% { --power: 0; }
  29.1667% { --power: 1; }
  37.5% { --power: 0.15; }
  75% { --power: 1; }
  100% { --power: 1; }
}

4. Dead letters and contrast

A broken tube is not invisible: it is grey-tinted glass. The unlit color is the tube color mixed into the wall, just strong enough to reach 3:1 against it, the WCAG minimum for large text, which a sign always is. A dip in the flicker goes at most to that color, so the panel's contrast figure is the floor at the dimmest moment. The glow is not counted; it only adds light around the letters.

The text is split into as few spans as the flicker and the dead letter need. A sign without either stays a single text node. Splitting a word into spans is invisible to most screen readers, but some (VoiceOver on iOS in particular) may read separately styled parts as separate words, which is one more reason to flicker only a single letter.

Browser support and performance

text-shadow is Baseline widely available since 2015. color-mix() is Baseline widely available too, and @property is Baseline since July 2024; without it the flicker still works, as explained above. Checked in Chromium and Firefox; Safari is untested.

  • Big blur radii on big text are the cost. Static, they are painted once. The stepped flicker repaints a single letter a few times per cycle.
  • The drop-shadow chain blurs offscreen copies of the text, one per layer; prefer text-shadow for long text or many signs.
  • Keep layers low (3 or 4 is plenty): the outer layers add the least light.

Back to the demo ↑