GLITCH LAB v1.0 ezolab.dev / lab instrument SYS: READY โœฆ Holiday cards

Effects/ Neon Border [FX_08]/ Calibrated

Neon Border

Copies a link to this page with your text and settings โ€” whoever opens it sees the same effect. Send it to a friend, a colleague or save it for later.
Pure CSS Light ยท zero deps #animation#button#neon

CSS neon glow border on a button: two highlights run around the tube, and now and then it flickers out and ignites again. Pure CSS, any text.

Live viewport Optical bench
LIVE FEED 60.0 FPS | FRAME: 16.7ms RES: โ€” [ + calibrated ]
Type any word: the preview changes at once, and so do the HTML you copy, the .zip and CodePen. Leave it empty to get the default word back.

How it works // breakdown

Spec-FX_08

This is a CSS neon glow border: a button framed by a neon tube, with two highlights running around the border towards each other โ€” and now and then the tube dies with a flicker and ignites again with a flash, like a real sign. Pure CSS, no JavaScript, no SVG. It works on a <button> or a link, grows with its text, and every setting is a CSS variable you can change live. Below: how the glowing border and the running highlights work, the settings, and the traps.

Why this effect

This is the frame from the panels on this site, turned into a button. Most animated glowing borders spin one gradient round and round forever โ€” after a few seconds you stop seeing it. A neon tube is more alive: it has a hot spot that travels, and once in a while it fails and comes back. The flicker at ignition is my favourite part; it's what makes it look like glass and gas, not like a gradient.

What you'll build

A dark button with a lime word. Its border is a thin bright line with a soft glow outside and inside. Two highlights slide along the border from opposite sides โ€” one bright with a white-hot centre, one dimmer. Every few seconds the tube flickers out in a third of a second, stays dark for a moment and ignites with four quick flickers and a short flash. The word itself stays lit, so the button is always readable.

How the neon border works

1. The button: padding is the gap to the tube

The button is an ordinary element with position: relative; the tube and the highlights are its ::after and ::before, so the HTML stays one tag. Everything is in em from the text size, so a longer or bigger label gets a bigger tube.

.nb-btn {
  position: relative;
  padding: 0.35em 0.8em;   /* space between the word and the tube */
  border: 0;
  border-radius: 0.25em;
  background: #0e1012;
  font: 700 72px "Space Grotesk", system-ui, sans-serif;
  color: #d4ff00;
  text-shadow: 0 0 0.17em rgb(212 255 0 / 0.6);
}

2. The tube: one border, four shadows

A neon glow border is mostly box-shadow. The line itself is a 2px border on the ::after; then a 1px spread ring thickens it a little, a tight glow and a wide faint glow light the air around it, and an inset glow lights the inside of the button โ€” real tubes light both sides.

.nb-btn::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  border: 2px solid rgb(212 255 0 / 0.85);
  box-shadow:
    0 0 0 1px rgb(212 255 0 / 0.25),
    0 0 0.25em 2px rgb(212 255 0 / 0.5),
    0 0 0.83em rgb(212 255 0 / 0.2),
    inset 0 0 0.25em rgb(212 255 0 / 0.2);
}
Border only, then with the outer glow, then with the inner glow too

3. Running highlights: a conic gradient and a mask

The highlights are a conic-gradient on the ::before โ€” a pie of colour around the centre that is transparent almost everywhere and bright in one narrow slice. A mask cuts out the middle and leaves only a 4px ring along the edge: content-box is the inside (the element has padding: 4px), and mask-composite: exclude keeps what is not inside.

.nb-btn::before {
  inset: -2px;
  padding: 4px;
  background:
    conic-gradient(from var(--nb-a), transparent 78%,
      #d4ff00 86%, #fff 91%, #d4ff00 95%, transparent),
    conic-gradient(from calc(180deg - var(--nb-a)),
      transparent 86%, #d4ff00 93%, transparent);
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask-composite: exclude;
}

The second gradient turns the other way (180deg - angle), so the two highlights run towards each other, meet and pass.

4. Spinning an angle with @property

You can't animate conic-gradient(from โ€ฆ) directly โ€” the browser sees a whole new image every frame. But you can animate a custom property if you tell the browser its type:

@property --nb-a {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}
@keyframes nb-spin { to { --nb-a: 360deg; } }

Now --nb-a is a real angle that goes from 0 to 360 degrees, and the gradients that use it turn with it. On a wide button the highlights slow down on the short sides and speed up on the long ones โ€” a conic gradient turns at a steady angle, not at a steady distance. It reads as light running along glass.

5. Dying and igniting: flicker as numbers

In the video the flicker is keyframes in an 8-second cycle. On a real page you want to choose how long the tube stays lit, and keyframes would stretch the flicker along with the pause. So the full version runs a clock โ€” --nb-t from 0 to 1 per cycle โ€” and --nb-s is the seconds since the tube started to die. Each flicker is one jump in brightness: an amount times a 0 โ†’ 1 ramp.

--nb-s: calc(var(--nb-t) * (var(--nb-pause) + 2.1) - var(--nb-pause));
--nb-o: calc(1
  - 0.8 * clamp(0, var(--nb-s) / 0.064, 1)            /* drops */
  + 0.6 * clamp(0, (var(--nb-s) - 0.064) / 0.04, 1)   /* catches */
  /* ...eight more jumps... */);

The tube and the highlights use opacity: var(--nb-o), and at full ignition filter: brightness() flashes to 2 and settles. The flicker always takes the same 2.1 seconds; --nb-pause only changes how long the tube burns between failures. The same clock is explained in How to Add a Pause Between CSS Animation Loops.

Make it yours

Variable What it does
--nb-pause Seconds the tube stays lit before it flickers out again.
--nb-lap Seconds for the highlights to go round. 2โ€“3 s is busy, 10 s is calm.
--nb-glow Glow strength: 0.5 is a thin line, 2 is a sign seen in fog.
--nb-size Text size; padding, corners and glow follow it.
--nb-color Tube and word colour.
--nb-flash The hot centre of the bright highlight.

Spacing: padding is the space between the word and the tube (in em, so it grows with the text); margin: 0 is the space around the button on your page โ€” set your own.

Gotchas

  • Glow gets cut off: a parent with overflow: hidden clips the outer glow. Give the parent some padding or let it overflow.
  • mask-composite: exclude is the standard name; very old Safari only knows -webkit-mask-composite: xor. Without it you'd see a filled pie instead of a ring.
  • The pause is a <number>: write --nb-pause: 10, not 10s.
  • Readability: only the tube flickers; the word stays lit. If you make the word flicker too, the button is unreadable for a moment โ€” fine for a sign, bad for a call to action.

Accessibility

It's a real <button> (or <a>), so it's focusable and works with the keyboard; :focus-visible adds a quiet ring outside the tube. The glow and the flicker are decoration only. With prefers-reduced-motion: reduce the tube just glows: no running highlights, no flicker.

Variations

  • The same tube as letters: Neon Sign โ€” neon text with one failing letter.
  • The same yellow phosphor behind glass: CRT Screen.
  • Highlights only, no flicker: set --nb-pause: 60.

FAQ

How do I make a neon glow border in CSS?

Give the element a thin bright border and several box-shadows in the same colour: a tight one, a wide faint one and an inset one for the inside. Put it on a pseudo-element if you want to animate the tube without touching the text.

How do I animate a glowing border in CSS?

Use a conic-gradient on a pseudo-element, cut it down to a ring with mask and mask-composite: exclude, and spin the gradient's starting angle โ€” registered with @property so it can be animated. No JavaScript needed.

How do I make a neon button flicker?

Animate the tube's opacity through a few quick drops and recoveries: down to 0.2, up to 0.8, down to 0.1, up to 0.6, off. Igniting is the same in reverse with a short brightness() flash at the end. Keep the word itself lit so the button stays readable.

Does the glowing border work on any size?

Yes โ€” everything is in em from the text size, so a small nav link and a big hero button get a tube in proportion. Only the line width and the 4px highlight ring stay in px, like a real tube's thickness.

Get the code โ€” copy or download
Copy HTML: the markup with your text โ€” paste it where the effect should be. Copy CSS: the styles with your slider settings โ€” paste into your stylesheet. Any text element works: give it the class and a data-text equal to its text.
or
โ†“ Download .zip Both files in one archive โ€” index.html and style.css โ€” with your text and settings. Unzip and open index.html in a browser.
/* Neon Border โ€” a button framed by a neon tube. Pure CSS.
   Two highlights run around the tube towards each other; now and then
   the tube dies with a flicker, stays dark for a moment and ignites
   again with a flash, like a real neon tube.
   Works on <button> and <a>: class="nb-btn" + data-text.
   Everything is sized in em from --nb-size, so the button grows with
   its text. Font: Space Grotesk (Google Fonts), falls back to system-ui.
   Settings: change the variables below. */
.nb-btn {
  --nb-pause: 6;        /* seconds the tube stays lit between flicker-outs */
  --nb-lap: 6;          /* seconds for the highlights to go round */
  --nb-glow: 1;         /* glow strength, 0.2 โ€“ 2 */
  --nb-size: 72px;      /* text size; the button follows it */
  --nb-color: #d4ff00;  /* tube and word */
  --nb-flash: #ffffff;  /* hot centre of the highlights */

  position: relative;
  margin: 0;                /* margin: space around the button on your page */
  padding: 0.35em 0.8em;    /* padding: space between the word and the tube */
  border: 0;
  border-radius: 0.25em;
  background: #0e1012;
  font: 700 var(--nb-size) "Space Grotesk", system-ui, sans-serif;
  color: var(--nb-color);
  text-shadow: 0 0 calc(0.17em * var(--nb-glow))
    color-mix(in srgb, var(--nb-color) 60%, transparent);
  text-decoration: none;
  cursor: pointer;

  /* A clock: --nb-t runs 0 โ†’ 1 once per cycle (lit + 2.1 s off and on) */
  animation: nb-clock calc((var(--nb-pause) + 2.1) * 1s) linear infinite;
  /* --nb-s: seconds since the tube started to die (negative while lit) */
  --nb-s: calc(var(--nb-t) * (var(--nb-pause) + 2.1) - var(--nb-pause));
  /* Tube brightness: dies in 0.3 s with four flickers, dark until 1.6 s,
     ignites with four flickers. Each line is one jump: amount ร— ramp. */
  --nb-o: calc(1
    - 0.8 * clamp(0, var(--nb-s) / 0.064, 1)
    + 0.6 * clamp(0, (var(--nb-s) - 0.064) / 0.04, 1)
    - 0.7 * clamp(0, (var(--nb-s) - 0.104) / 0.056, 1)
    + 0.5 * clamp(0, (var(--nb-s) - 0.16) / 0.04, 1)
    - 0.6 * clamp(0, (var(--nb-s) - 0.2) / 0.08, 1)
    + 0.5 * clamp(0, (var(--nb-s) - 1.6) / 0.08, 1)
    - 0.45 * clamp(0, (var(--nb-s) - 1.68) / 0.04, 1)
    + 0.65 * clamp(0, (var(--nb-s) - 1.72) / 0.08, 1)
    - 0.6 * clamp(0, (var(--nb-s) - 1.8) / 0.04, 1)
    + 0.9 * clamp(0, (var(--nb-s) - 1.84) / 0.08, 1));
  /* ...and when it's fully on, a flash that settles */
  --nb-b: calc(1
    + clamp(0, (var(--nb-s) - 1.84) / 0.08, 1)
    - clamp(0, (var(--nb-s) - 1.92) / 0.18, 1));
}

/* The tube: a line and its glow, inside and out */
.nb-btn::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  border: 2px solid color-mix(in srgb, var(--nb-color) 85%, transparent);
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--nb-color) 25%, transparent),
    0 0 calc(0.25em * var(--nb-glow)) 2px color-mix(in srgb, var(--nb-color) 50%, transparent),
    0 0 calc(0.83em * var(--nb-glow)) color-mix(in srgb, var(--nb-color) 20%, transparent),
    inset 0 0 calc(0.25em * var(--nb-glow)) color-mix(in srgb, var(--nb-color) 20%, transparent);
  opacity: var(--nb-o);
  filter: brightness(var(--nb-b));
  pointer-events: none;
}

/* Two highlights run towards each other. A conic gradient spins
   (--nb-a); the mask keeps only a 4px ring along the edge. */
.nb-btn::before {
  content: "";
  position: absolute;
  inset: -2px;
  z-index: 1;
  padding: 4px;
  border-radius: inherit;
  background:
    conic-gradient(from var(--nb-a), transparent 78%,
      var(--nb-color) 86%, var(--nb-flash) 91%, var(--nb-color) 95%, transparent),
    conic-gradient(from calc(180deg - var(--nb-a)),
      transparent 86%, var(--nb-color) 93%, transparent);
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask-composite: exclude;
  opacity: var(--nb-o);
  filter: brightness(var(--nb-b));
  pointer-events: none;
  animation: nb-spin calc(var(--nb-lap) * 1s) linear infinite;
}

/* Keyboard focus: a quiet ring outside the tube */
.nb-btn:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--nb-color) 50%, transparent);
  outline-offset: 0.2em;
}

@property --nb-a {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}
@keyframes nb-spin {
  to { --nb-a: 360deg; }
}
@property --nb-t {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}
@keyframes nb-clock {
  to { --nb-t: 1; }
}

/* Less motion: the tube just glows โ€” no highlights, no flicker. */
@media (prefers-reduced-motion: reduce) {
  .nb-btn,
  .nb-btn::before { animation: none; }
}