Skip to content

Eclipse Slide

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
<!-- Eclipse Slide — a dark disc slides over the sun to represent dark mode -->
<button class="nuda-tt2-eclipse" type="button" aria-pressed="true" aria-label="Toggle theme">
  <span class="nuda-tt2-eclipse__stage" aria-hidden="true">
    <span class="nuda-tt2-eclipse__corona"></span>
    <span class="nuda-tt2-eclipse__sun"></span>
    <span class="nuda-tt2-eclipse__moon"></span>
  </span>
</button>
JavaScript
/* Eclipse Slide — toggle aria-pressed to slide the moon over the sun. */
(function () {
  var btn = document.querySelector('.nuda-tt2-eclipse');
  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-eclipse {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #0a0a0a;
  border: 1px solid rgba(255,255,255,.08);
  cursor: pointer;
  overflow: hidden;
}

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

.nuda-tt2-eclipse__stage {
  position: relative;
  width: 28px;
  height: 28px;
}

.nuda-tt2-eclipse__corona {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(228,255,84,.15),0 0 18px 4px rgba(228,255,84,.35);
  opacity: 0;
  transition: opacity .5s ease;
}

.nuda-tt2-eclipse[aria-pressed="true"] .nuda-tt2-eclipse__corona {
  opacity: 1;
}

.nuda-tt2-eclipse__sun {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%,#fff8dc,#fbbf24);
  box-shadow: 0 0 14px #fbbf24;
}

.nuda-tt2-eclipse__moon {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: #0a0a0a;
  border: 1px solid rgba(255,255,255,.12);
  transform: translateX(-42px);
  transition: transform .6s cubic-bezier(.4,0,.2,1);
}

.nuda-tt2-eclipse[aria-pressed="true"] .nuda-tt2-eclipse__moon {
  transform: translateX(0);
}

@media (prefers-reduced-motion:reduce) {
  .nuda-tt2-eclipse__moon,.nuda-tt2-eclipse__corona {
    transition: none;
  }
}

How to use Eclipse Slide

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