Skip to content
Added 2 Sept 2026
Back to library
day-night-switch-15849
Day Night Switch
Micro-interactions

Day Night Switch

Theme toggle where the amber sun travels across the track, cools to pale grey and has a bite taken out of it by an offset disc so it lands as a crescent moon over a sky that has meanwhile filled with stars.

Micro-interactionsthemetogglesuncrescentcheckbox
lines of CSS
77lines of CSS
dependencies
0dependencies
browser, for years
Everybrowser, for years
motion only on interaction
Hovermotion only on interaction
Backdrop
Open a live copy in

Vue, Svelte, styled-components and Tailwind exports are part of Pro. HTML, CSS and React are free forever.

day-night-switch-15849.css
.fx-v14-mi-theme-15848 {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
}
.fx-v14-mi-theme-15848 input { position: absolute; opacity: 0; width: 0; height: 0; }
.fx-v14-mi-theme-15848 .tr {
  position: relative;
  display: block;
  width: 62px;
  height: 32px;
  border-radius: 999px;
  overflow: hidden;
  background: linear-gradient(180deg, #172554, #0b1220);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.6);
}
.fx-v14-mi-theme-15848 .tr::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #7dd3fc, #38bdf8);
  transition: opacity 0.4s ease;
}
.fx-v14-mi-theme-15848 .st {
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #e2e8f0;
  opacity: 0;
  transition: opacity 0.4s ease 0.1s;
}
.fx-v14-mi-theme-15848 .st.a { left: 12px; top: 8px; }
.fx-v14-mi-theme-15848 .st.b { left: 20px; top: 20px; width: 2px; height: 2px; }
.fx-v14-mi-theme-15848 .st.d { left: 30px; top: 11px; width: 2px; height: 2px; }
.fx-v14-mi-theme-15848 .kn {
  position: absolute;
  left: 3px;
  top: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fbbf24;
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.75);
  transition: transform 0.45s cubic-bezier(0.5, 1.4, 0.5, 1), background 0.4s ease, box-shadow 0.4s ease;
}
.fx-v14-mi-theme-15848 .kn::after {
  content: '';
  position: absolute;
  top: -5px;
  right: -5px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: #101c36;
  transform: scale(0);
  transform-origin: 72% 28%;
  transition: transform 0.45s cubic-bezier(0.5, 1.4, 0.5, 1);
}
.fx-v14-mi-theme-15848 em {
  font-style: normal;
  font-size: 0.78rem;
  color: #94a3b8;
  transition: color 0.3s ease;
}
.fx-v14-mi-theme-15848:hover .kn { box-shadow: 0 0 16px rgba(251, 191, 36, 0.9); }
.fx-v14-mi-theme-15848:hover em { color: #e2e8f0; }
.fx-v14-mi-theme-15848 input:checked ~ .tr::before { opacity: 0; }
.fx-v14-mi-theme-15848 input:checked ~ .tr .st { opacity: 1; }
.fx-v14-mi-theme-15848 input:checked ~ .tr .kn {
  transform: translateX(30px);
  background: #e2e8f0;
  box-shadow: 0 0 12px rgba(226, 232, 240, 0.5);
}
.fx-v14-mi-theme-15848 input:checked ~ .tr .kn::after { transform: scale(1); }
.fx-v14-mi-theme-15848:hover input:checked ~ .tr .kn { box-shadow: 0 0 18px rgba(226, 232, 240, 0.65); }
day-night-switch-15849.html
<label class="fx-v14-mi-theme-15848">
  <input type="checkbox" />
  <span class="tr">
    <i class="st a"></i>
    <i class="st b"></i>
    <i class="st d"></i>
    <span class="kn"></span>
  </span>
  <em>Dark mode</em>
</label>

What do I do with this?

  1. Put day-night-switch-15849.css anywhere your page already loads CSS from — in Next.js that is app/globals.css, or any stylesheet with a <link> in your HTML.
  2. Then put the class on the element you want it on: <button class="fx-v14-mi-theme-15848">. The CSS does nothing until a class name in it matches something on the page.
  • Link the stylesheet, then paste the markup wherever you need it.
npx hoverlab add day-night-switch-15849

What's included

  • The markup and the stylesheet, in whichever framework you pick
  • No runtime dependencies

Works with

  • React
  • Vue
  • Svelte
  • Tailwind
  • styled-components
  • Plain CSS

npx hoverlab add day-night-switch-15849

Or over MCP, from your editor's agent — no account needed.

License

Free to read, copy and install, for personal and non-commercial projects. Shipping it in client work or a paid product needs Pro ($79 once). The source lands in your repo and stops being ours — no attribution, nothing to upgrade.

Was this useful?

Motion safety

Static estimate, read from the CSS

Reduced motion
Brief motion, no guard

Animates briefly or on interaction. Only looping motion gets a guard in this catalog; copy the one from the Insights tab if this ships on a critical path.

What it animates
Repaints

Animates background, box-shadow, color. No reflow, but the browser repaints every frame, which is fine for one element and costly across many.

Flashing (WCAG 2.3.1)
No flashing found

No repeating change in opacity, colour or brightness large enough to count as a flash.

Layout shift (CLS)
No shift expected

Nothing it animates moves or resizes the box in flow. A category from the CSS, not a measurement for this effect.

Every row is read from the shipped CSS. Only a figure marked measured came from a browser. Customizing the speed changes the timing, so recheck a customized copy. How it is computed

34 more effects in Micro-interactions

All of them free to read, copy and install — no account, no locked tiles, no watermarked preview. The whole catalog is open, and so are the API and the CLI.

Browse Micro-interactions

Shipping one commercially

Copying the code is free. Putting it in client work or a paid product is what Pro is for — the licence, not the access.

  • A commercial licence for everything in the catalog
  • Unlimited bundle exports, in Vue, Svelte and Tailwind
  • One payment — no subscription, nothing to renew
Pro — $79 once

7 variations of Day Night Switch

Finished looks, each one a position in the customizer above. Copy any of them, or open it and keep moving the sliders.