Skip to content
animorio
IT
Back to the library

Dark mode switch

Transitions, HoverGSAP, CSS onlyMediumCompressed weight: Demo 7.2 KBGSAP 28 KBFreeDownload the zip

The settings of a reading app, in the clean style of today’s apps: turn on dark mode and the light of the page pulls back into the toggle, with a soft edge like a lamp’s, leaving the glass cards lit only by the small warm light of the knob. Turn it off and the light pours out of the toggle again and fills the page.

The code

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

<!doctype html>
<!--
  "Dark mode switch" 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>Settings that switch to dark mode as the light retreats into the toggle</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>
  <main class="stage" data-stage>
    <!-- the settings of a reading app: flip Appearance and the light pulls back into the toggle,
         leaving the glass cards lit only by the small lamp of the knob; flip it again and the light pours out -->
    <div class="scene" data-scene>
      <div class="layer layer--dark" data-layer="dark"></div>
      <div class="layer layer--light" data-layer="light"></div>
    </div>

    <template data-panel>
      <section class="panel">
        <header class="panel__head" data-row>
          <span class="brand">
            <svg viewBox="0 0 24 24" aria-hidden="true"><path class="brand__frame" d="M8 4.5h8M9 4.5v2.2M15 4.5v2.2M7.2 8.2c0-1 .8-1.5 1.8-1.5h6c1 0 1.8.5 1.8 1.5v8.6c0 1.3-1 2.2-2.3 2.2H9.5c-1.3 0-2.3-.9-2.3-2.2Z"/><path class="brand__flame" d="M12 10.2c1.4 1.5 2 2.6 2 3.6a2 2 0 0 1-4 0c0-1 .6-2.1 2-3.6Z"/></svg>
            Lanternly
          </span>
          <span class="panel__title">Settings</span>
        </header>

        <div class="card card--main" data-row>
          <div class="row row--theme">
            <span class="row__icon">
              <svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="7.5"/><path d="M12 4.5a7.5 7.5 0 0 1 0 15Z" class="fill"/></svg>
            </span>
            <span class="row__text">
              <span class="row__name">Appearance</span>
              <span class="row__value"><span class="roll" data-roll><span>Light</span><span>Dark</span></span></span>
            </span>
            <button class="switch" data-switch type="button" role="switch" aria-checked="false" aria-label="Dark mode">
              <span class="switch__track"></span>
              <span class="switch__knob" data-knob>
                <span class="switch__glow"></span>
                <svg class="sun" data-sun viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="4"/><path d="M12 3v2.2M12 18.8V21M3 12h2.2M18.8 12H21M5.6 5.6l1.6 1.6M16.8 16.8l1.6 1.6M5.6 18.4l1.6-1.6M16.8 7.2l1.6-1.6"/></svg>
                <svg class="moon" data-moon viewBox="0 0 24 24" aria-hidden="true"><path d="M18.5 14.6A7 7 0 0 1 9.4 5.5a7 7 0 1 0 9.1 9.1Z"/></svg>
              </span>
            </button>
          </div>
          <div class="row" data-hover>
            <span class="row__icon"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 5.5h8.5a3 3 0 0 1 3 3v10H9a3 3 0 0 1-3-3Z"/><path d="M9 9.5h5.5M9 12.5h4"/></svg></span>
            <span class="row__text"><span class="row__name">Reading font</span><span class="row__value">Serif, 18 pt</span></span>
            <svg class="chev" viewBox="0 0 24 24" aria-hidden="true"><path d="m10 7 5 5-5 5"/></svg>
          </div>
          <div class="row" data-hover>
            <span class="row__icon"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 4.5v3M12 16.5v3M4.5 12h3M16.5 12h3"/><circle cx="12" cy="12" r="2.4"/></svg></span>
            <span class="row__text"><span class="row__name">Warm light after sunset</span><span class="row__value">From 7:40 PM</span></span>
            <span class="pill">On</span>
          </div>
        </div>

        <div class="card" data-row>
          <div class="row" data-hover>
            <span class="row__icon"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M7 16.5a4 4 0 0 1-.4-8 5.5 5.5 0 0 1 10.6 1.4 3.4 3.4 0 0 1-.7 6.6Z"/></svg></span>
            <span class="row__text"><span class="row__name">Sync library</span><span class="row__value">412 books, 3 devices</span></span>
            <svg class="chev" viewBox="0 0 24 24" aria-hidden="true"><path d="m10 7 5 5-5 5"/></svg>
          </div>
          <div class="row row--bar" data-hover>
            <span class="row__icon"><svg viewBox="0 0 24 24" aria-hidden="true"><rect x="5" y="6" width="14" height="12" rx="2.5"/><path d="M5 10.5h14"/></svg></span>
            <span class="row__text"><span class="row__name">Storage</span><span class="bar"><i></i></span></span>
            <span class="row__num">2.4 of 5 GB</span>
          </div>
        </div>
      </section>
    </template>

    <svg class="ghost" data-ghost viewBox="0 0 24 24" aria-hidden="true"><path d="M5 3.2 19.2 11l-6.3 1.6-3.3 5.9Z"></path></svg>
  </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.

16 values to change

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 “Dark mode switch” 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

On a light page, lit from above by a warm light, sit the settings of Lanternly, a reading app: the appearance row with the toggle, the reading font, warm light after sunset, library sync and the storage used with its bar. The drawn pointer passes over the rows, which light up slightly, then presses the toggle: the knob squashes, runs on a spring with a pixel too much, the sun spins away as the moon arrives, and the label under Appearance rolls from Light to Dark. Meanwhile the light of the page pulls back towards the toggle with a soft edge, and each row shifts a few pixels and settles as the edge crosses it, the farthest first. In the dark the cards of dark glass remain: the last light goes into the knob, which lights up like a small lamp, flares once and calms down, and its warm glow tints the glass and the edges of the nearest cards. The pointer passes over the rows again and presses once more: the light pours out of the toggle and fills the page, and the lamp of the knob goes out.

How it works

Two pages, one over the other

The settings are a template copied twice: the dark version below, the light one on top. Everything that moves (knob, icons, rolling label, rows) moves together in both copies, so at any moment the two pages are the same except for their colours.

The light as a mask

The light copy has a radial mask-image centred on the toggle: solid up to r0, transparent at r, with r0 equal to r times 1 minus FEATHER. GSAP takes r from the radius that covers the farthest corner down to zero in LIGHT_TIME seconds, and the light pulls back with a soft edge like a lamp’s; on the way back it does the opposite.

The lamp of the knob

In the dark theme every card has two radial gradients centred on the toggle: one inside, barely warm, and one on the border, cut out with mask-composite, that makes the nearest edges catch the light. Their strength is a CSS variable that rises as the last light arrives, flares once and settles on GLOW.

Rows crossed by the edge

Each row has a delay worked out from its distance from the toggle: as the edge of the light crosses it, it shifts by ROW_NUDGE pixels and returns to its place with back.out.

The knob on a spring

On press the knob widens from the side it starts on, runs with back.out in KNOB_TIME seconds and turns round again with elastic.out; the sun and the moon swap places turning ninety degrees.

Values to change

NameFileDefaultWhat it changes
LIGHT_TIMEscript.js1.15The seconds in which the light pulls back into the toggle, or pours out of it.
FEATHERscript.js0.32How soft the edge of the light is, as a share of the radius.
KNOB_TIMEscript.js0.5The seconds of the knob’s run on its spring.
ROW_NUDGEscript.js7How many pixels each row shifts as the light crosses it.
GLOWscript.js1How much glow the lamp of the knob leaves on the glass.
PAUSEscript.js1.6The seconds of pause of the drawn pointer at the end of a round.

Try them in the Playground

When to use it

For the settings of an app or a site with a dark theme, when the switch should feel like a light going out rather than a plain swap of colours; for the page of a reading or evening app; or to present a product’s new dark theme.

On phones

The same settings sized on the height and width of the box, the same light pulling back into the toggle, which is pressed with a finger.

With reduced motion

The knob and the icons go to their place without a run, the light page fades out over the dark one or comes back, with no retreating light and no shifting rows; the drawn pointer is hidden.

Pitfalls

  • The soft edge of the mask starts before the radius: so that the light page also covers the farthest corner, the starting radius is the distance to that corner divided by 1 minus FEATHER.
  • Hovering the copy on top does not light the copy underneath: rows light up in pairs, at the same position in both copies.
  • The centre of the light and the glow on the cards are in pixels: they are recomputed on every resize.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

Tested on 28 October 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 animations