Skip to content

Desk Lamp Glow

A copy-paste theme toggle component in pure HTML, CSS & vanilla JS. Zero dependencies, framework-agnostic, MIT-licensed.

Theme ToggleHTMLJavaScriptCSSany framework

Copy into your project

HTML
<!-- Desk Lamp Glow — click to bloom a warm glow behind the lamp icon -->
<button class="nuda-tt2-lamp" type="button" aria-pressed="true" aria-label="Toggle theme">
  <span class="nuda-tt2-lamp__bloom" aria-hidden="true"></span>
  <svg class="nuda-tt2-lamp__shade" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
    <path d="M4 3 L20 3 L16 11 L8 11 Z" />
    <rect x="11" y="11" width="2" height="7" />
    <rect x="7" y="18" width="10" height="2" rx="1" />
  </svg>
  <span class="nuda-tt2-lamp__bulb" aria-hidden="true"></span>
</button>
JavaScript
/* Desk Lamp Glow — toggle aria-pressed to bloom the glow and light the bulb. */
(function () {
  var btn = document.querySelector('.nuda-tt2-lamp');
  if (!btn) return;
  btn.addEventListener('click', function () {
    var pressed = btn.getAttribute('aria-pressed') === 'true';
    btn.setAttribute('aria-pressed', String(!pressed));
    document.documentElement.classList.toggle('dark', !pressed);
  });
})();
CSS
.nuda-tt2-lamp {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 10px;
  color: #8a8a8a;
  cursor: pointer;
  transition: color .4s ease,border-color .4s ease;
}

.nuda-tt2-lamp:focus-visible {
  outline: 2px solid #e4ff54;
  outline-offset: 2px;
}

.nuda-tt2-lamp__shade {
  position: relative;
  z-index: 2;
  width: 22px;
  height: 22px;
}

.nuda-tt2-lamp[aria-pressed="true"] {
  color: #fbbf24;
  border-color: rgba(251,191,36,.35);
}

.nuda-tt2-lamp__bloom {
  position: absolute;
  width: 20px;
  height: 20px;
  top: 8px;
  border-radius: 50%;
  background: radial-gradient(circle,rgba(251,191,36,.55),transparent 70%);
  opacity: 0;
  transform: scale(.6);
  transition: opacity .4s ease,transform .4s ease;
}

.nuda-tt2-lamp[aria-pressed="true"] .nuda-tt2-lamp__bloom {
  opacity: 1;
  transform: scale(1);
  animation: nuda-tt2-lamp-breathe 2.6s ease-in-out infinite;
}

.nuda-tt2-lamp__bulb {
  position: absolute;
  width: 5px;
  height: 5px;
  top: 16px;
  border-radius: 50%;
  background: transparent;
  transition: background .4s ease,box-shadow .4s ease;
}

.nuda-tt2-lamp[aria-pressed="true"] .nuda-tt2-lamp__bulb {
  background: #fff8dc;
  box-shadow: 0 0 8px 2px #fbbf24;
}

@keyframes nuda-tt2-lamp-breathe {
  0%,100% {
    transform: scale(1);
    opacity: .85;
  }
  50% {
    transform: scale(1.15);
    opacity: 1;
  }
}

@media (prefers-reduced-motion:reduce) {
  .nuda-tt2-lamp__bloom {
    animation: none;
  }
  .nuda-tt2-lamp,.nuda-tt2-lamp__shade,.nuda-tt2-lamp__bloom,.nuda-tt2-lamp__bulb {
    transition: none;
  }
}

How to use Desk Lamp Glow

Paste the HTML where you need it and the CSS into a global stylesheet (or a <style> tag). Every class is prefixed nuda- so it never collides with Tailwind or your own styles. Tweak the CSS custom properties to match your design system.

Works in React, Vue, Svelte, Astro, Next.js, Nuxt, Laravel Blade, Django, Rails — or a single .html file. No npm install, no build step.

More theme toggle components

← Browse all NudaUI components