AI CSS Animations

Light Bulb Checkbox

A light bulb that switches on: the glass flickers to full, the filament glows white, a soft halo spreads and five rays fan out from the center. Unchecking dims it straight back to an outline.

Also known as: light bulb toggle css, lamp icon checkbox, idea bulb animation css.

HTML

<label class="chk-light-bulb">
  <input type="checkbox">
  <span class="chk-light-bulb-icon" aria-hidden="true">
    <i class="chk-light-bulb-glow"></i>
    <span class="chk-light-bulb-rays"><i style="--a:-64deg;--d:2"></i><i style="--a:-32deg;--d:1"></i><i style="--a:0deg;--d:0"></i><i style="--a:32deg;--d:1"></i><i style="--a:64deg;--d:2"></i></span>
    <svg class="chk-light-bulb-bulb" viewBox="0 0 24 24"><path class="chk-light-bulb-glass" d="M9.2 16.2c0-2.2-3.4-3.8-3.4-7.7a6.2 6.2 0 0 1 12.4 0c0 3.9-3.4 5.5-3.4 7.7z"/><path d="M9.6 19h4.8M10.6 21.4h2.8"/><path class="chk-light-bulb-filament" d="M10.4 16l-.9-4.6 1.5 1 1-1 1 1 1.5-1-.9 4.6"/></svg>
  </span>
  <span class="chk-light-bulb-text">Desk lamp</span>
</label>

CSS

.chk-light-bulb {
  --c: var(--chk-color, #3b82f6);
  font-size: var(--chk-size, 24px);
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  line-height: 1.3;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.chk-light-bulb input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}
.chk-light-bulb-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 1.8em;
  height: 1.8em;
  border-radius: 0.35em;
}
.chk-light-bulb-glow {
  position: absolute;
  left: 50%;
  top: 37%;
  width: 2.4em;
  height: 2.4em;
  margin: -1.2em;
  border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--c) 35%, transparent), transparent);
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.chk-light-bulb-rays i {
  position: absolute;
  left: 50%;
  top: 37%;
  width: 0.1em;
  height: 0.26em;
  margin: -0.13em -0.05em;
  border-radius: 1em;
  background: var(--c);
  transform: rotate(var(--a)) translateY(-0.95em) scaleY(0);
  transition: transform 0.15s ease-in;
}
.chk-light-bulb-bulb {
  position: relative;
  width: 1.8em;
  height: 1.8em;
  color: color-mix(in srgb, currentColor 70%, transparent);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: color 0.25s ease;
}
.chk-light-bulb-glass {
  fill: var(--c);
  fill-opacity: 0;
  transition: fill-opacity 0.25s ease;
}
.chk-light-bulb-filament {
  transition: stroke 0.25s ease;
}
.chk-light-bulb-text {
  transition: color 0.25s ease;
}
.chk-light-bulb:hover .chk-light-bulb-bulb {
  color: var(--c);
}
.chk-light-bulb input:checked + .chk-light-bulb-icon .chk-light-bulb-bulb {
  color: var(--c);
}
.chk-light-bulb input:checked + .chk-light-bulb-icon .chk-light-bulb-glass {
  fill-opacity: 1;
  animation: chk-light-bulb-flicker 0.6s linear;
}
.chk-light-bulb input:checked + .chk-light-bulb-icon .chk-light-bulb-filament {
  stroke: #fff;
}
.chk-light-bulb input:checked + .chk-light-bulb-icon .chk-light-bulb-glow {
  opacity: 1;
  transform: scale(1);
  transition: opacity 0.5s ease 0.35s, transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.35s;
}
.chk-light-bulb input:checked + .chk-light-bulb-icon .chk-light-bulb-rays i {
  transform: rotate(var(--a)) translateY(-0.95em) scaleY(1);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) calc(0.4s + var(--d) * 0.06s);
}
.chk-light-bulb input:checked ~ .chk-light-bulb-text {
  color: var(--c);
}
.chk-light-bulb input:focus-visible + .chk-light-bulb-icon {
  outline: 0.12em solid var(--c);
  outline-offset: 0.18em;
}
@keyframes chk-light-bulb-flicker {
  0% { fill-opacity: 0.15; }
  15% { fill-opacity: 1; }
  25% { fill-opacity: 0.3; }
  40% { fill-opacity: 1; }
  50% { fill-opacity: 0.6; }
  60%, 100% { fill-opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .chk-light-bulb, .chk-light-bulb *, .chk-light-bulb::before, .chk-light-bulb::after, .chk-light-bulb *::before, .chk-light-bulb *::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