Animated theme toggle

Mood track «Kawai Kitsune» · Kevin MacLeod incompetech.com · licensed under Creative Commons BY 4.0
Example image of the style Animated theme toggle
Preview built in HTML and CSS in this style

Cambio de tema animado · Theme toggle · Dark mode toggle · Interruttore sole e luna · Light-dark switch

Pressing the switch turns the sun into a moon and the whole interface shifts from light to dark with a circular wipe or a soft fade. A small detail that makes a site memorable.

Era
2019 – today
Use
Mainstream
Domain
Web / UIMotion
Mood
playfulcalmclean
Explore

Live demo

View code
<main class="ui">
  <header><b>Diario</b>
    <button class="tg" aria-label="Cambia tema"><svg viewBox="0 0 40 40">
      <mask id="m"><rect width="40" height="40" fill="#fff"/><circle class="bite" cx="34" cy="8" r="9" fill="#000"/></mask>
      <circle class="core" cx="20" cy="20" r="8" mask="url(#m)"/>
      <g class="rays"><path d="M20 3v4M20 33v4M3 20h4M33 20h4M8 8l3 3M29 29l3 3M8 32l3-3M29 11l3-3"/></g>
    </svg></button>
  </header>
  <article><h1>Una passeggiata al tramonto</h1><p>Il cielo cambiava colore a ogni passo, dal rosa all'indaco.</p><div class="tags"><span>viaggi</span><span>appunti</span></div></article>
</main>
<script>
const ui=document.querySelector('.ui'),b=document.querySelector('.tg');b.onclick=()=>ui.classList.toggle('dark');
if(matchMedia('(prefers-reduced-motion: no-preference)').matches)setInterval(()=>ui.classList.toggle('dark'),2600);
</script>
body{margin:0;height:100vh;display:grid;place-items:center;background:#E9E1CC;font-family:Nunito,sans-serif}
.ui{--bg:#FDF6E3;--fg:#1B1E2B;--card:#fff;--mut:#1B1E2B99;--ic:#FFB703;width:380px;max-width:92vw;border-radius:22px;background:var(--bg);color:var(--fg);padding:16px 20px 22px;box-sizing:border-box;box-shadow:0 24px 40px -24px #1B1E2B88;position:relative;overflow:hidden}
.ui.dark{--bg:#1B1E2B;--fg:#F2EFE6;--card:#2C3045;--mut:#F2EFE699;--ic:#8EA7FF}
header{display:flex;justify-content:space-between;align-items:center;font-size:18px}
.tg{width:46px;height:46px;border-radius:50%;border:0;background:var(--card);padding:6px;cursor:pointer;box-shadow:0 4px 12px -4px #0004}
svg{width:100%;height:100%;display:block;overflow:visible}
.core{fill:var(--ic)}
.rays path{stroke:var(--ic);stroke-width:2.6;stroke-linecap:round;fill:none}
.rays{transform-origin:20px 20px}
.dark .core{transform-origin:20px 20px;transform:scale(1.55)}
.dark .bite{transform:translate(-9px,5px)}
.dark .rays{transform:rotate(90deg) scale(0);opacity:0}
article{margin-top:16px;background:var(--card);border-radius:16px;padding:16px}
h1{font-size:21px;font-weight:800;margin:0 0 6px}
p{margin:0 0 12px;font-size:14px;line-height:1.45;color:var(--mut)}
.tags span{display:inline-block;font-size:12px;font-weight:700;padding:3px 10px;border-radius:99px;margin-right:6px;background:var(--bg);color:var(--ic)}
@media (prefers-reduced-motion:no-preference){
  .ui,article,.tg,.tags span,p{transition:background .6s ease,color .6s ease}
  .core,.bite,.rays{transition:transform .55s cubic-bezier(.68,-.55,.27,1.55),opacity .35s,fill .6s,stroke .6s}
}

Characteristics

  • Sun and moon icons morphing into each other
  • Rays rotating and retracting
  • Interface colours transitioning through variables
  • Circular reveal starting from the switch
  • Saved preference respecting the system theme

Palette

Click a swatch to copy it

Typography

Headings · Nunito Animated theme toggle

Body · Nunito Pressing the switch turns the sun into a moon and the whole interface shifts from light to dark with a circular wipe or a soft fade. A small detail that makes a site memorable.

Motion

Easing
cubic-bezier(0.68, -0.55, 0.27, 1.55) per l'icona; ease per i colori
Typical duration
400–600 ms per l'icona; 300–800 ms per il cambio di tema
Techniques
variabili CSS sul root, View Transitions API con clip-path circle, SVG mask per la luna, transform rotate e scale sui raggi, prefers-color-scheme e localStorage

Accessibility (reduced motion)

The theme switches instantly or with a brief fade; the icon swaps from sun to moon without rotating.

Prompt for your agent

Copy and paste into your prompt to have an agent or image generator reproduce this style.

For web pages and UI

Design the web page or interface in this style: Animated theme toggle (Cambio de tema animado, Theme toggle).
Pressing the switch turns the sun into a moon and the whole interface shifts from light to dark with a circular wipe or a soft fade. A small detail that makes a site memorable.
Characteristics: Sun and moon icons morphing into each other, Rays rotating and retracting, Interface colours transitioning through variables, Circular reveal starting from the switch, Saved preference respecting the system theme.
Palette: #FDF6E3, #1B1E2B, #FFB703, #8EA7FF, #2C3045, #E9E1CC.
Typography: headings in Nunito, body text in Nunito (Google Fonts or equivalents).
Mood: playful, calm, clean.
Motion: easing cubic-bezier(0.68, -0.55, 0.27, 1.55) per l'icona; ease per i colori, typical duration 400–600 ms per l'icona; 300–800 ms per il cambio di tema; techniques: variabili CSS sul root, View Transitions API con clip-path circle, SVG mask per la luna, transform rotate e scale sui raggi, prefers-color-scheme e localStorage.
With prefers-reduced-motion: The theme switches instantly or with a brief fade; the icon swaps from sun to moon without rotating.
References: Interruttori tema dei blog tecnici, toggles animati di theme-toggles.dev, View Transitions API, macOS Mojave (2018) e l'arrivo del dark mode.

Relations

Derives from: Micro-interactionsMicro-interactionsSimilar to: Dark Mode UIDark Mode UISimilar to: View TransitionsView TransitionsAnimated theme toggle
Derives fromSimilar toSee in the graph →

References

  • Interruttori tema dei blog tecnici
  • toggles animati di theme-toggles.dev
  • View Transitions API
  • macOS Mojave (2018) e l'arrivo del dark mode