A dim glass tube on a dark panel that flickers to life like a neon sign when you switch it on: the outline and knob light up in your accent with layered glow. Box-shadow and opacity only.
Also known as: neon glow toggle switch, glowing switch css, cyberpunk toggle switch.
<label class="tgl-neon"> <input type="checkbox" role="switch" aria-label="Sign lights"> <span class="tgl-neon-track" aria-hidden="true"></span> </label>
.tgl-neon {
--c: var(--tgl-color, #3b82f6);
font-size: var(--tgl-size, 24px);
position: relative;
display: inline-block;
vertical-align: middle;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
padding: 1.1em 1.4em;
border-radius: 1em;
background: #0d0d14;
box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.07);
}
.tgl-neon input {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
margin: 0;
opacity: 0;
cursor: pointer;
z-index: 1;
}
.tgl-neon-track {
position: relative;
display: block;
width: 4em;
height: 2em;
border: 0.14em solid color-mix(in srgb, var(--c) 35%, transparent);
border-radius: 1em;
transition: border-color 0.2s ease, box-shadow 0.3s ease;
}
.tgl-neon-track::before {
content: "";
position: absolute;
top: 0.21em;
left: 0.21em;
width: 1.3em;
height: 1.3em;
border: 0.14em solid color-mix(in srgb, var(--c) 45%, transparent);
border-radius: 50%;
transition:
transform 0.4s cubic-bezier(0.3, 0.7, 0.3, 1),
background-color 0.3s ease,
border-color 0.3s ease,
box-shadow 0.3s ease;
}
.tgl-neon input:checked + .tgl-neon-track {
border-color: var(--c);
box-shadow: 0 0 0.3em var(--c), 0 0 1em color-mix(in srgb, var(--c) 55%, transparent), inset 0 0 0.4em color-mix(in srgb, var(--c) 55%, transparent);
animation: tgl-neon-flicker 0.8s linear;
}
.tgl-neon input:checked + .tgl-neon-track::before {
border-color: var(--c);
background: color-mix(in srgb, var(--c) 45%, #fff);
box-shadow: 0 0 0.25em var(--c), 0 0 0.8em var(--c);
transform: translateX(2em);
}
.tgl-neon input:focus-visible + .tgl-neon-track {
outline: 2px solid var(--c);
outline-offset: 0.25em;
}
@keyframes tgl-neon-flicker {
0% { opacity: 0.3; }
8% { opacity: 1; }
14% { opacity: 0.35; }
22% { opacity: 1; }
30% { opacity: 0.55; }
38%, 100% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
.tgl-neon, .tgl-neon *, .tgl-neon::before, .tgl-neon::after, .tgl-neon *::before, .tgl-neon *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--tgl-color on the element or a parent.
Currently previewing #3b82f6.--tgl-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 24px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.