Skip to content
animorio
IT
Back to the library

Weather day to night

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

The theme change of a whole made-up weather app, Calder: turn the switch in the bar and in the sky at the top the sun goes down along its arc and under the horizon while the moon rises on the other side, the sky goes through the colours of sunset to the night, and then the light of the sky runs down the interface as a soft band with a hairline in the middle: every part of the app changes colour as the line reaches it, from the top to the bottom, and the data follow. The other way round it is the sunrise, with the pink of the morning. Minimal, in the style of a product interface.

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>
<!--
  "Weather day to night" 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 weather app that turns from day to night as the sun sets</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>
    <!-- Calder, a made-up weather app. The sky at the top is the source of the theme: when the switch is turned the
         sun goes down along its arc, the moon comes up on the other side, and the light of the sky runs down the
         interface like a line of dusk, changing every part of the app as it passes it, from the top to the bottom -->
    <div class="app" data-app>
      <span class="app__flood" data-flood aria-hidden="true"></span>
      <span class="app__band" data-band aria-hidden="true"><span class="app__edge"></span></span>

      <header class="bar zone" data-zone>
        <div class="bar__place">
          <span class="bar__city">Lisbon</span>
          <span class="bar__time" data-clock>14:20</span>
        </div>
        <button class="switch" type="button" role="switch" aria-checked="false" aria-label="Night theme" data-switch>
          <span class="switch__track" aria-hidden="true"></span>
          <span class="switch__knob" data-knob aria-hidden="true">
            <svg viewBox="0 0 16 16">
              <defs>
                <mask id="knob-moon">
                  <rect width="16" height="16" fill="#fff"/>
                  <circle data-bite cx="15" cy="1" r="4" fill="#000"/>
                </mask>
              </defs>
              <g class="switch__rays" data-rays>
                <path d="M8 1.6v1.5M8 12.9v1.5M1.6 8h1.5M12.9 8h1.5M3.5 3.5l1 1M11.5 11.5l1 1M3.5 12.5l1-1M11.5 4.5l1-1"/>
              </g>
              <circle class="switch__core" data-core cx="8" cy="8" r="3.3" mask="url(#knob-moon)"/>
            </svg>
          </span>
        </button>
      </header>

      <section class="sky zone" data-zone aria-label="Sky">
        <svg class="sky__svg" viewBox="0 0 209 104" preserveAspectRatio="xMidYMid slice" aria-hidden="true">
          <defs>
            <linearGradient id="g-day" x1="0" y1="0" x2="0" y2="1">
              <stop offset="0" stop-color="#4f8fe0"/>
              <stop offset="0.62" stop-color="#9cc8f2"/>
              <stop offset="1" stop-color="#e4eef8"/>
            </linearGradient>
            <linearGradient id="g-dusk" x1="0" y1="0" x2="0" y2="1">
              <stop offset="0" stop-color="#34407e"/>
              <stop offset="0.55" stop-color="#b9687f"/>
              <stop offset="0.86" stop-color="#f29a62"/>
              <stop offset="1" stop-color="#f7c08a"/>
            </linearGradient>
            <linearGradient id="g-dawn" x1="0" y1="0" x2="0" y2="1">
              <stop offset="0" stop-color="#5a6fae"/>
              <stop offset="0.58" stop-color="#d9a3b6"/>
              <stop offset="1" stop-color="#fbd9c2"/>
            </linearGradient>
            <linearGradient id="g-night" x1="0" y1="0" x2="0" y2="1">
              <stop offset="0" stop-color="#060a18"/>
              <stop offset="0.6" stop-color="#101a38"/>
              <stop offset="1" stop-color="#1e2c52"/>
            </linearGradient>
            <radialGradient id="g-sun-glow">
              <stop offset="0" stop-color="#fff3d6" stop-opacity="0.9"/>
              <stop offset="0.35" stop-color="#ffd59a" stop-opacity="0.35"/>
              <stop offset="1" stop-color="#ffb36b" stop-opacity="0"/>
            </radialGradient>
            <radialGradient id="g-moon-glow">
              <stop offset="0" stop-color="#dfe7ff" stop-opacity="0.45"/>
              <stop offset="1" stop-color="#9db6ff" stop-opacity="0"/>
            </radialGradient>
            <linearGradient id="g-haze" x1="0" y1="0" x2="0" y2="1">
              <stop offset="0" stop-color="#fff" stop-opacity="0"/>
              <stop offset="1" stop-color="#fff" stop-opacity="0.22"/>
            </linearGradient>
            <clipPath id="above">
              <rect x="0" y="0" width="209" height="86"/>
            </clipPath>
            <mask id="moon-cut">
              <rect x="-20" y="-20" width="40" height="40" fill="#fff"/>
              <circle cx="3.4" cy="-2.6" r="6.2" fill="#000"/>
            </mask>
          </defs>
          <rect class="sky__layer" width="209" height="104" fill="url(#g-day)" data-layer="day"/>
          <rect class="sky__layer" width="209" height="104" fill="url(#g-dusk)" data-layer="dusk" opacity="0"/>
          <rect class="sky__layer" width="209" height="104" fill="url(#g-dawn)" data-layer="dawn" opacity="0"/>
          <rect class="sky__layer" width="209" height="104" fill="url(#g-night)" data-layer="night" opacity="0"/>
          <rect width="209" height="86" fill="url(#g-haze)"/>
          <path class="sky__arc" d="M30.5 86A74 74 0 0 1 178.5 86"/>
          <g clip-path="url(#above)">
            <g data-sun>
              <circle r="26" fill="url(#g-sun-glow)" data-sun-glow/>
              <circle r="8.2" class="sky__sun" data-sun-core/>
              <circle r="8.2" class="sky__sun-rim"/>
            </g>
            <g data-moon>
              <circle r="20" fill="url(#g-moon-glow)"/>
              <circle r="6.6" class="sky__moon" mask="url(#moon-cut)"/>
            </g>
          </g>
          <line class="sky__horizon" x1="10" y1="86" x2="199" y2="86"/>
          <line class="sky__tick" x1="30.5" y1="84" x2="30.5" y2="88"/>
          <line class="sky__tick" x1="178.5" y1="84" x2="178.5" y2="88"/>
          <text class="sky__label" x="12" y="97.5">Sunrise 07:21</text>
          <text class="sky__label" x="197" y="97.5" text-anchor="end">Sunset 17:24</text>
        </svg>
      </section>

      <section class="now zone" data-zone>
        <p class="now__temp"><span data-temp>21</span><span class="now__deg">°</span></p>
        <div class="now__words">
          <p class="now__cond"><span class="swap" data-swap><span class="swap__a">Mostly sunny</span><span class="swap__b">Clear night</span></span></p>
          <p class="now__range">H 22°&#8195;L 11°</p>
        </div>
      </section>

      <section class="card hours zone" data-zone aria-label="Next hours">
        <div class="hours__row" data-hours></div>
      </section>

      <section class="card chart zone" data-zone aria-label="Temperature today">
        <div class="chart__head">
          <span class="chart__title">Temperature</span>
          <span class="chart__read" data-read>21° at 14:20</span>
        </div>
        <div class="chart__plot" data-plot>
        <svg class="chart__svg" viewBox="0 0 200 44" preserveAspectRatio="none" data-chart aria-hidden="true">
          <defs>
            <linearGradient id="g-area" x1="0" y1="0" x2="0" y2="1">
              <stop offset="0" class="chart__stop-a"/>
              <stop offset="1" class="chart__stop-b"/>
            </linearGradient>
          </defs>
          <line class="chart__grid" x1="0" y1="43.5" x2="200" y2="43.5"/>
          <line class="chart__grid" data-noon x1="100" y1="2" x2="100" y2="43.5"/>
          <path class="chart__area" data-area/>
          <path class="chart__line" data-line/>
          <line class="chart__drop" data-drop y2="43.5"/>
        </svg>
        <span class="chart__dot" data-dot aria-hidden="true"></span>
        </div>
        <div class="chart__axis" aria-hidden="true"><span>00</span><span>06</span><span>12</span><span>18</span><span>24</span></div>
      </section>

      <div class="stats zone" data-zone>
        <div class="card stat">
          <svg class="stat__icon" viewBox="0 0 16 16" aria-hidden="true"><path d="M2 6h8.2a2.2 2.2 0 1 0-2.2-2.2M2 9.5h10.6a2 2 0 1 1-2 2M2 13h5"/></svg>
          <span class="stat__name">Wind</span>
          <span class="stat__value"><span data-wind>12</span> km/h</span>
        </div>
        <div class="card stat">
          <svg class="stat__icon" viewBox="0 0 16 16" aria-hidden="true"><path d="M8 2.2c2.4 3 3.9 5.2 3.9 7.2a3.9 3.9 0 0 1-7.8 0c0-2 1.5-4.2 3.9-7.2z"/></svg>
          <span class="stat__name">Humidity</span>
          <span class="stat__value"><span data-hum>58</span>%</span>
        </div>
      </div>

      <nav class="tabs zone" data-zone aria-label="Sections">
        <a class="tab is-on" href="#" aria-current="page">
          <svg viewBox="0 0 16 16" aria-hidden="true"><circle cx="6" cy="6" r="2.4"/><path d="M6 1.4v1M1.4 6h1M2.8 2.8l.7.7M9.2 2.8l-.7.7M5.2 13.6h6.3a2.7 2.7 0 0 0 .3-5.4 3.6 3.6 0 0 0-6.8 1.2 2.1 2.1 0 0 0 .2 4.2z"/></svg>
          <span>Today</span>
        </a>
        <a class="tab" href="#">
          <svg viewBox="0 0 16 16" aria-hidden="true"><path d="M1.8 3.6l4-1.6 4.4 1.8 4-1.6v10.2l-4 1.6-4.4-1.8-4 1.6zM5.8 2v10.2M10.2 3.8V14"/></svg>
          <span>Radar</span>
        </a>
        <a class="tab" href="#">
          <svg viewBox="0 0 16 16" aria-hidden="true"><path d="M4 2h8v12l-4-3-4 3z"/></svg>
          <span>Places</span>
        </a>
      </nav>
    </div>
    <p class="sr" aria-live="polite" data-live></p>
  </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.

49 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 “Weather day to night” 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

In the middle of the page sits Calder, the weather app for Lisbon: at the top the bar with the city, the time and the theme switch, then the sky in a rounded card, with a blue gradient, the dotted arc of the sun, the horizon with the two ticks of sunrise and sunset and the warm white sun with its halo; below the big temperature, the next five hours with their icons, the temperature chart of the day with the point of now, wind and humidity and the tab bar. The switch turns: the knob squashes, runs a pixel too far and the sun inside it becomes a moon. In the sky the sun goes down along the arc, warms to orange and disappears under the horizon while the moon rises on the other side and settles; the sky goes through the pink and orange of sunset to the blue of night. Then a band of warm light with a hairline in the middle comes down the app from the top: the ground changes with a soft edge and every part, as the band reaches it, takes the colours of the night, moves a pixel down and settles. Meanwhile the clock runs to 21:40, the temperature falls from 21 to 14 degrees, «Mostly sunny» becomes «Clear night», the hours one after the other turn to moon icons, the point on the chart runs along the curve, wind and humidity change. Turning it back is the sunrise: the moon goes on along its way and sets on the right, the sun rises from the left in the pink of the morning and the light comes down again. Over the chart the point follows the pointer and the line at the top reads the temperature of that hour. Left alone, the switch turns by itself, day and night.

How it works

Every part is a zone with its own colours

The bar, the sky, the temperature, the hours, the chart, the two stats and the tabs each have their own CSS variables (--card, --fg, --mut, --line, --acc and the shadows): inside each zone everything is coloured with those. GSAP can interpolate colours in CSS variables, so a zone changes theme with a single tween, without touching the rest.

The sky in SVG

Four rectangles with gradients (day, sunset, sunrise, night) on top of each other, of which only the opacity changes. Sun and moon sit on an arc: x = cx + r cos(a), y = cy − r sin(a), and GSAP runs the angle. A clipPath cuts everything below the horizon, so the sun really sets. The bodies always travel from left to right: at sunrise the moon goes on past the top and the sun comes up again from the left.

The line of light

A band with a warm gradient and a one pixel hairline comes down with a linear y from above the app to below it. With it a layer with the new ground is uncovered from the top with a gradient mask-image, whose soft edge follows the band.

The moment of each zone

Since the band moves at a constant speed, the moment it reaches a zone comes from the zone’s position: t = delay + duration × (top of the zone / height + 0.15) / 1.3. There the zone’s colour change starts, with a one pixel push down that settles back.

The data that follow

The time, the temperature, wind and humidity are numbers in an object that GSAP runs; every frame they are written rounded. The point on the chart reads the height of the curve from a table taken from the path with getPointAtLength, and at sunrise it wraps past midnight with a fade at the edges.

The switch and the chart under the pointer

The knob squashes, runs with back.out and comes back round on a spring; a black circle in a mask bites the sun and turns it into a moon. Over the chart the point follows the pointer with quickTo and the line at the top reads the temperature of that hour; leaving, it goes back to the hour of now on a spring.

Values to change

NameFileDefaultWhat it changes
SKY_TIMEscript.js2.4The seconds the sun and the moon take to cross the sky.
LIGHT_DELAYscript.js0.8The seconds after the switch before the light starts coming down the app.
LIGHT_TIMEscript.js1.9The seconds the line of light takes from the top of the app to the bottom.
ZONE_FADEscript.js0.7The seconds each part takes to change colour as the light reaches it.
NUDGEscript.js1.2The pixels each part moves down as the light passes, before it settles back.
BANDscript.js1How visible the band of light is (0 = no band, only the colours change).
HOLDscript.js2.6The seconds the app stays in day or night before the switch turns by itself.
LOOPscript.jstrueThe switch turns by itself, day and night, again and again.

Try them in the Playground

When to use it

For an app or a site with light and dark themes, when the change should tell something and not be a plain swap of colours: a weather, travel, notes, sleep or meditation app, a dashboard with a night mode, a hotel page that goes from the day to the evening.

On phones

The same animation: the whole app is measured in em of a font size taken from its height, which is measured on the height and width of the window, so it stays whole even in a short, wide box. The point on the chart is worked out every frame on the real size. With a finger, a touch on the chart reads the hour like the pointer.

With reduced motion

No setting sun and no running band: the colours of the whole app change together in a fade, the sun fades away and the moon appears already in its place, and the numbers are the new ones at once.

Pitfalls

  • CSS variables only interpolate if GSAP knows the starting value: here every zone gets the day colours with gsap.set first, otherwise the first change starts from an empty string and jumps.
  • The chart uses preserveAspectRatio none to fill the card: the point is not in the SVG (it would turn into an oval) but in an HTML element on top, placed with the real size of the box every frame.
  • At sunrise the time runs forward, not back: from 21:40 to 14:20 of the next day, so the number runs past 1440 minutes and is brought back into the day at the end, and the point on the chart does the same past 24.
  • mask-image still wants the -webkit- prefix for Safari.
  • The digits need font-variant-numeric: tabular-nums, otherwise the running clock makes the line shake.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

Tested on 11 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 animations