Skip to content
animorio
IT
All components

Light mode button

Buttons, Hover, TransitionsGSAP, CSS onlyMediumCompressed weight: Demo 6.6 KBGSAP 28 KBFreeDownload the zip

A real button for the light theme, a pill with the icon and the label: on the dark theme it says «Light mode» with a thin moon. Tap it and it squeezes on a spring, the moon turns, the bite of the crescent slides away and the body shrinks into the core of a sun, the rays fan open one after another, a degree past their place, and settle. From the centre of the icon a warm light spreads in a circle over the whole page, and the example card behind turns to the light theme with it; the label becomes «Dark mode». A second tap brings the night back the same way. A single sun-coloured accent.

The code

A folder that runs on its own: index.html, style.css, script.js and the libraries from a CDN. The React and Vue tabs hold the same demo as a ready component, which switches its animations off when it leaves the page.

<!doctype html>
<!--
  "Light mode button" from Animorio · https://animorio.com
  License: free on your own sites and your clients’ sites, paid work included.
  Not for resale, redistribution, templates or code collections · https://animorio.com/en/license/
-->
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Light mode button</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/wdth.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <!-- the light that spreads from the icon over the page when the theme changes -->
  <span class="flood" data-flood aria-hidden="true"></span>

  <main class="stage">
    <div class="group" data-gruppo>
    <!-- a small page card behind the button, so the change of theme has something to land on -->
    <article class="note" data-note aria-label="Example page">
      <span class="note__edge" aria-hidden="true"></span>
      <span class="note__kicker">Field journal</span>
      <h1 class="note__title">Evening on the ridge</h1>
      <p class="note__line">The wind drops after six and the valley goes quiet.</p>
      <p class="note__line note__line--short">Two more miles to the hut.</p>
    </article>

    <!-- the light mode button: a real pill with the icon and the label -->
    <button class="pill" type="button" aria-pressed="false" data-pill>
      <span class="pill__bg" data-bg aria-hidden="true"></span>
      <span class="pill__shine" data-shine aria-hidden="true"></span>
      <span class="pill__in">
        <svg class="icon" data-icon viewBox="0 0 24 24" aria-hidden="true">
          <defs>
            <mask id="falce" maskUnits="userSpaceOnUse" x="0" y="0" width="24" height="24">
              <rect width="24" height="24" fill="#fff"/>
              <circle data-bite cx="16.6" cy="7.4" r="6.4" fill="#000"/>
            </mask>
          </defs>
          <g data-rays></g>
          <circle class="icon__body" data-body cx="12" cy="12" r="7.2" mask="url(#falce)"/>
        </svg>
        <span class="pill__labels" data-labels>
          <span class="pill__label" data-to-light>Light mode</span>
          <span class="pill__label" data-to-dark aria-hidden="true">Dark mode</span>
        </span>
      </span>
    </button>
    </div>
  </main>

  <script src="https://cdn.jsdelivr.net/npm/gsap@3.15.0/dist/gsap.min.js"></script>
  <script src="script.js"></script>
</body>
</html>

Playground

Change values, colours and text with the controls and watch the animation respond live. Or write in the code yourself. Then download the folder with your changes.

17 values to change

Works with Claude, Claude Code, ChatGPT, Cursor, VS Code, Windsurf, Codex, Gemini CLI

Or ask your AI assistant for it

With the Animorio connector, Claude Code, ChatGPT, Cursor or VS Code take it from here, guide included, and fit it into your project. Paste this request:

Take “Light mode button” from Animorio and fit it into my site
Platform licenseFree on your sites and your clients’ sites. Want it inside a website builder, a template platform or a client dashboard? There’s a license for agencies and platforms.

What it does

The page is black, with an example card («Evening on the ridge») and below it the «Light mode» pill with the moon. On hover the body of the pill swells, the label widens and the moon turns a little. Tap and the pill squeezes and springs back; the moon turns back, the bite of the crescent slides away and the body shrinks into the core of the sun; the sun-coloured rays open one after another, go a degree too far and settle. From the centre of the icon a white light with a warm rim spreads in a circle to the corners of the page; the card and the pill take the light theme as the light passes, and «Light mode» lifts away as «Dark mode» arrives. A thread of light runs along the edge of the pill. The second tap does the opposite: the rays fold away, the moon comes back and the night spreads in a circle.

How it works

Moon and sun are one icon

A circle with a mask: with the bite of the mask inside it is a crescent, with the bite moved out and the radius going from 7.2 to 4.6 it is the core of the sun. The rays are lines drawn around the true centre (12, 12) and turned with svgOrigin.

The light starts at the icon

A fixed circle under the page, centred on the measured centre of the icon and as big as the distance to the farthest corner, scales from zero to one; it is a radial gradient with the colour of the new theme and a warm rim.

The theme is variables

The colours of page, card and pill are CSS variables on the root: GSAP takes them from the dark to the light theme as the light passes, and at the end only the .chiaro class is left.

The label widens nothing

«Light mode» and «Dark mode» sit on top of each other, absolutely positioned, inside a box as wide as the longer one, measured: icon and label stay in the centre of the pill in every state.

Values to change

NameFileDefaultWhat it changes
RAYSscript.js8How many rays open around the sun, from 4 to 12.
FILLscript.js0.95Seconds for the light (or the night) to cover the page.
SPRINGscript.js0.5How springy the press and the rays are (lower = more bounce).
RAY_STAGGERscript.js0.045Seconds between one ray and the next as they fan open.
START_LIGHTscript.jsfalseStart in the light theme instead of the dark one.
IDLEscript.js6Seconds after your last touch before the demo plays by itself again.

Try them in the Playground

When to use it

On a site or app with a dark and a light theme: in the top bar, in the settings menu or at the bottom of the page, when changing theme should be a button with its own label rather than a switch.

On phones

Everything is in em and the size depends on both the width and the height of the window; the light is measured on every tap from the true centre of the icon, so it covers the page at any size.

With reduced motion

No circle of light, no springs and no fanning rays: the icon swaps with a fade and the page fades to the other theme.

Pitfalls

  • A userSpaceOnUse mask does not turn with the circle: to turn the moon on hover the whole icon turns, with transformOrigin at 50%, because the svg is an element of the page.
  • The two labels of the button are absolute and only GSAP sets their transform (yPercent −50): a translate in the CSS would add to it.
  • The circle of light must be measured on every tap: the demo window changes size while you watch it.
  • Enter and Space on a real button already arrive as a click: no second keyboard handler.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

Compressed with gzip, the three demo files weigh 6.6 KB; the libraries: GSAP 28 KB.

Testing

Tested on 30 November 2026

  • Desktop: Done
  • Phone: Done
  • Reduced motion: Done
  • Safari on iPhone: To do

License

Use it in your own projects and in your clients’ projects. Do not resell it or redistribute it as is. GSAP stays under its own Standard license. Full license.

All components