AI CSS Animations

Neon Glow Checkbox

A neon tube checkbox on its own dark panel: checking flickers the box on like a sign warming up, draws a glowing tick and lights the label. Glow comes from box-shadow and a drop-shadow filter.

Also known as: glowing checkbox css, neon checkbox, glow checkbox.

HTML

<label class="chk-neon-checkbox">
  <input type="checkbox">
  <span class="chk-neon-checkbox-box">
    <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>
  </span>
  <span class="chk-neon-checkbox-text">Night mode</span>
</label>

CSS

.chk-neon-checkbox {
  --c: var(--chk-color, #3b82f6);
  font-size: var(--chk-size, 24px);
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.3;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  --glow: color-mix(in srgb, var(--c) 55%, #fff);
  gap: 0.75em;
  padding: 0.75em 1.25em;
  border-radius: 0.75em;
  background: #0b0d17;
  color: #94a3b8;
  letter-spacing: 0.02em;}
.chk-neon-checkbox input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}
.chk-neon-checkbox-box {
  box-sizing: border-box;
  display: grid;
  place-items: center;
  flex: none;
  width: 1.375em;
  height: 1.375em;
  border: 0.1em solid color-mix(in srgb, var(--c) 80%, transparent);
  border-radius: 0.3em;
  box-shadow: 0 0 0 transparent, inset 0 0 0 transparent;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}
.chk-neon-checkbox-box svg {
  display: block;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  width: 0.9em;
  height: 0.9em;
  stroke: var(--glow);
  stroke-width: 3;
  stroke-dasharray: 22;
  stroke-dashoffset: 22;
  filter: drop-shadow(0 0 0.12em var(--c));
  transition: stroke-dashoffset 0.15s ease-in;
}
.chk-neon-checkbox-text {
  transition: color 0.3s ease, text-shadow 0.3s ease;
}
.chk-neon-checkbox input:checked + .chk-neon-checkbox-box {
  border-color: var(--glow);
  box-shadow: 0 0 0.5em var(--c), inset 0 0 0.35em color-mix(in srgb, var(--c) 60%, transparent);
  animation: chk-neon-checkbox-flicker 0.6s linear;
}
.chk-neon-checkbox input:checked + .chk-neon-checkbox-box svg {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.3s ease-out 0.25s;
}
.chk-neon-checkbox input:checked ~ .chk-neon-checkbox-text {
  color: #fff;
  text-shadow: 0 0 0.5em var(--c);
}
.chk-neon-checkbox input:focus-visible + .chk-neon-checkbox-box {
  outline: 0.125em solid var(--c);
  outline-offset: 0.18em;
}
@keyframes chk-neon-checkbox-flicker {
  0%, 100% { opacity: 1; }
  8% { opacity: 0.3; }
  16% { opacity: 1; }
  28% { opacity: 0.45; }
  40% { opacity: 1; }
  52% { opacity: 0.75; }
}

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

Customizing this snippet

  • Color: set --chk-color on the element or a parent. Currently previewing #3b82f6.
  • Size: set --chk-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 24px.
  • 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 checkboxes