Skip to content
animorio
IT
All components

Sun and moon theme picker

Pickers, Hover, SVGGSAP, CSS onlyMediumCompressed weight: Demo 7.9 KBGSAP 28 KBFreeDownload the zip

The Appearance panel in the settings of an invented reading app, Halden: a Light, Dark and Auto segmented control. A single orb rides the pill and changes shape on a real spring: the sun pulls in its rays one by one as a shadow bites it into a crescent moon, and Auto stops halfway, a twilight. Meanwhile the panel itself takes on the chosen theme, the page thumbnail splits diagonally for Auto and the line below rolls to its new text.

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>
<!--
  "Sun and moon theme picker" 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>The light, dark and auto theme picker with a sun that turns into a moon on a spring</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">
    <!-- the appearance setting of an invented reading app, Halden: one orb rides the pill and becomes sun, twilight or moon,
         while the panel itself takes the tone of the chosen theme -->
    <section class="panel" data-panel aria-labelledby="ttl">
      <span class="panel__sheen" aria-hidden="true"></span>
      <header class="panel__head">
        <div class="panel__txt">
          <h2 class="panel__title" id="ttl">Appearance</h2>
          <p class="panel__sub">How Halden looks on this device</p>
        </div>
        <span class="thumb" data-thumb aria-hidden="true">
          <span class="thumb__page thumb__page--light"><i></i><i></i><i></i></span>
          <span class="thumb__page thumb__page--dark" data-thumb-dark><i></i><i></i><i></i></span>
        </span>
      </header>

      <div class="seg" role="radiogroup" aria-label="Theme" data-seg>
        <span class="seg__hover" data-hover aria-hidden="true"></span>
        <span class="seg__glow" data-glow aria-hidden="true"></span>
        <span class="seg__pill" data-pill aria-hidden="true"><span class="seg__shine"></span></span>
        <button class="seg__opt" type="button" role="radio" aria-checked="true" tabindex="0" data-opt="0">
          <svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="4"></circle><path d="M12 3.5v2M12 18.5v2M3.5 12h2M18.5 12h2M6 6l1.4 1.4M16.6 16.6 18 18M6 18l1.4-1.4M16.6 7.4 18 6"></path></svg>
          <span class="seg__lbl">Light</span>
        </button>
        <button class="seg__opt" type="button" role="radio" aria-checked="false" tabindex="-1" data-opt="1">
          <svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><path d="M19 14.6A7.5 7.5 0 0 1 9.4 5a7.5 7.5 0 1 0 9.6 9.6Z"></path></svg>
          <span class="seg__lbl">Dark</span>
        </button>
        <button class="seg__opt" type="button" role="radio" aria-checked="false" tabindex="-1" data-opt="2">
          <svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="7"></circle><path d="M12 5a7 7 0 0 1 0 14Z" class="ico__fill"></path></svg>
          <span class="seg__lbl">Auto</span>
        </button>
        <svg class="orb" data-orb viewBox="0 0 24 24" aria-hidden="true">
          <defs>
            <mask id="orbMask" maskUnits="userSpaceOnUse" x="0" y="0" width="24" height="24">
              <rect width="24" height="24" fill="#fff"></rect>
              <circle data-shade cx="30" cy="-6" r="6" fill="#000"></circle>
            </mask>
            <radialGradient id="orbFill" cx="38%" cy="34%" r="70%">
              <stop offset="0" stop-color="var(--orb-hi)"></stop>
              <stop offset="1" stop-color="var(--orb)"></stop>
            </radialGradient>
          </defs>
          <g data-rays></g>
          <circle data-disc cx="12" cy="12" r="4.4" fill="url(#orbFill)" mask="url(#orbMask)"></circle>
        </svg>
      </div>

      <p class="note"><span class="note__line" data-note aria-live="polite">Always light, easy on bright days</span></p>
    </section>

    <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.

26 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 “Sun and moon theme picker” 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 pure white sits the Appearance panel of Halden, an invented reading app: a title, a line, a page thumbnail on the right and below a track with three segments, Light, Dark and Auto, each with its outline icon. Over the chosen segment there is a light pill and, in place of its icon, a live orb: an orange sun with eight rays and a warm light fading under the pill. Pick Dark and the pill slides with its leading edge leaving first and landing a pixel too far; the orb follows on a spring of its own, a beat behind, while the rays pull in by pairs as the crown turns, the disc grows and a round shadow bites it until a silver crescent moon is left. The whole panel, track, pill and text, slides to the dark theme on the same spring, its top edge catches a thread of light and the thumbnail turns to night. Auto stops the orb halfway: short rays and a bite, twilight; the panel goes back to light (the system is in daytime now), the thumbnail splits diagonally and the line below says from what time it goes dark. Pressing the segment already chosen squeezes the pill and the orb winks along its spring. With the mouse over a segment a ghost pill appears; it works with touch and the arrow keys.

How it works

One orb, one number

Sun, twilight and moon are the same SVG driven by a single number, the phase: 0 the sun, 0.5 Auto, 1 the moon. The phase gives the disc radius, the length and rotation of the eight rays (they pull in by pairs, staggered) and the position of the black circle of a mask that bites the disc. The shadow distance is piecewise, so halfway there is already a readable bite.

A real spring

Phase, panel darkness, thumbnail cut and orb position are four springs integrated in requestAnimationFrame with stiffness and damping (STIFFNESS, DAMPING), the step capped at 1/30 of a second. When all of them rest the loop stops. The orb’s spring is a little stiffer than the pill, which runs on GSAP: it lands a beat later and sways a couple of pixels.

The panel takes the theme

Every panel colour has a light and a dark version in :root; gsap.utils.interpolate blends them with the darkness spring and the script rewrites the CSS variables. Being a spring, the colour goes just past and back, like everything else.

The stretching pill

The pill has two animated edges: the leading one leaves first and lands a pixel too far, the trailing one catches up, then half a wave sets them exact; the warm light under the pill follows the same edges. The Auto thumbnail is a dark page over a light one, cut by a slanted polygon clip-path.

The pilot

A drawn pointer picks Dark, then Auto, presses Auto again for the wink and goes back to Light. At the first real touch, click or key it stops.

Values to change

NameFileDefaultWhat it changes
SUNscript.js#f4a23aThe colour of the sun and of its light under the pill.
MOONscript.js#c9d2ecThe colour of the moon.
STIFFNESSscript.js210The stiffness of the spring moving sun, moon and colours.
DAMPINGscript.js0.62The spring damping: lower bounces more.
SLIDE_TIMEscript.js0.44Seconds for the pill to reach the segment.
SUNSETscript.js17:04The time Auto switches to dark.
PAUSEscript.js1.9Seconds the pilot stays on each theme.

Try them in the Playground

When to use it

In the settings of any app or site with a dark theme: reading apps, dashboards, editors, documentation sites, the account menu. The panel taking on the theme itself shows the choice before it is applied to the page.

On phones

Same animation: the panel takes almost the full width, margins also follow the height, the track stays 48 pixels tall, a comfortable finger target.

With reduced motion

Nothing slides or bounces: pill and orb fade out and back in on the new segment already in their final shape, the panel colours change at once and the line below crossfades.

Pitfalls

  • The orb stayed stuck on the left: its position was read from the icon’s offsetLeft, but an svg has no offsetLeft and gave NaN. Now it is measured with getBoundingClientRect against the track.
  • With the shadow approaching in a straight line, halfway (Auto) the sun was not bitten yet and Auto looked like Light: the shadow distance is piecewise, faster in the first half.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

Tested on 10 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