Skip to content
animorio
IT
Back to the library

Sunrise and sunset

SVG, HoverGSAP, CSS onlyMediumCompressed weight: Demo 6.3 KBGSAP 28 KBFreeDownload the zip

A city’s sunrise and sunset card, on warm white: a panel of sky with the sun’s dashed arc over the horizon, the sun running along it and the part already done drawn in white. Dragging across the sky moves the hour: the sun runs along the arc and drops below the horizon, the sky goes from the day’s blue to the orange of sunset to the blue of night, the big time changes and a line says how much daylight is left or how long until sunrise. The pill at the top names the moment: morning, golden hour, night. Minimal style.

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>
<!--
  "Sunrise and sunset" 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>Sunrise and sunset</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">
    <!-- a sunrise and sunset card: the sun's arc over the horizon, the sun running along it as you drag the hour,
         the sky changing colour and a line saying how much daylight is left -->
    <section class="ss" data-ss aria-label="Sunrise and sunset">
      <header class="ss__head">
        <div class="ss__what"><strong>Lisbon</strong><span>Wednesday 2 December</span></div>
        <span class="ss__pill"><span class="ss__clip"><span data-outphase>Afternoon</span></span></span>
      </header>

      <div class="ss__sky" data-sky role="slider" tabindex="0" aria-label="Time of day" aria-valuemin="0" aria-valuemax="24" aria-valuenow="13.67">
        <svg class="ss__svg" viewBox="0 0 320 150" preserveAspectRatio="none" aria-hidden="true">
          <defs>
            <clipPath id="ss-above"><rect x="0" y="0" width="320" height="112"></rect></clipPath>
          </defs>
          <rect data-air x="0" y="0" width="320" height="112"></rect>
          <g clip-path="url(#ss-above)">
            <path class="ss__arc" d="M40 112A120 84 0 0 1 280 112"></path>
            <path class="ss__done" data-done d="M40 112A120 84 0 0 1 280 112" pathLength="1"></path>
          </g>
          <rect class="ss__ground" data-ground x="0" y="112" width="320" height="38"></rect>
          <path class="ss__horizon" d="M0 112h320"></path>
          <path class="ss__tick" d="M40 108v8M280 108v8"></path>
          <line class="ss__hair" data-hair x1="0" x2="0" y1="0" y2="150"></line>
        </svg>
        <div class="ss__above" aria-hidden="true"><span class="ss__halo" data-halo></span><span class="ss__sun" data-sun></span></div>
        <span class="ss__at ss__at--rise" data-outrise>07:38</span>
        <span class="ss__at ss__at--set" data-outset>17:16</span>
      </div>

      <div class="ss__now">
        <p class="ss__time" role="timer"><b data-outtime>13:40</b></p>
        <span class="ss__left"><span class="ss__clip ss__clip--left"><span data-outleft>3 h 36 min of daylight left</span></span></span>
      </div>

      <dl class="ss__facts">
        <div><dt>Sunrise</dt><dd data-outrise2>07:38</dd></div>
        <div><dt>Sunset</dt><dd data-outset2>17:16</dd></div>
        <div><dt>Daylight</dt><dd data-outday>9 h 38 min</dd></div>
      </dl>
    </section>
    <span class="live" aria-live="polite" data-live></span>

    <svg class="ghost" data-ghost viewBox="0 0 24 24" aria-hidden="true"><path d="M5 3.200 19.200 11l-6.300 1.600-3.300 5.900Z"></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.

23 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 “Sunrise and sunset” 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 warm white, a rounded card: at the top “Lisbon”, “Wednesday 2 December” and on the right the pill of the moment, “Afternoon”. Below, a panel of pale blue sky with a dark band at the bottom for the ground: on the horizon two white ticks with the times, “07:38” on the left and “17:16” on the right, and between them a dashed arc. The sun is a yellow disc with its halo, resting on the arc at the current hour; the stretch of arc already travelled is a solid white line. Under the panel the big time, “13:40”, and on the right “3 h 36 min of daylight left”; at the bottom three facts: Sunrise, Sunset, Daylight “9 h 38 min”. At the start the sun climbs from sunrise to the current hour. Moving or dragging across the sky a vertical hairline appears and the hour follows it, in five-minute steps: the sun slides along the arc turning orange when it is low, the white line chases it, the sky fades towards the gold and orange of sunset and the pill rolls to “Golden hour”. Past sunset the sun goes down under the ground, the sky turns night blue, the pill says “Dusk” and then “Night” and the line “Sun rises in 12 h 22 min”. Going back to sunrise everything replays in reverse. The arrow keys move the hour by a quarter of an hour.

How it works

A single number, the hour

Everything comes from the hour: the sun’s place, how much arc is drawn, the sky’s colours, the written time, the daylight line and the moment of the day.

The sun on half an ellipse

By day the fraction between sunrise and sunset becomes an angle on the upper half of an ellipse; by night the sun carries on along the lower half, hidden by the ground.

The sky by stops

Ten colours pinned to the hours around sunrise and sunset: between one stop and the next the colour blends. Change the times and the sky follows them.

Dragging the day

The sky’s width is the whole day, midnight to midnight: the pointer picks the hour and a short spring takes the number there.

Values to change

NameFileDefaultWhat it changes
ACCENTscript.js#e8792bThe colour of the low sun and of golden hour.
RISEscript.js7.63The time of sunrise, in decimal hours (7.63 = 07:38).
SETscript.js17.27The time of sunset, in decimal hours (17.27 = 17:16).
NOWscript.js13.67The hour shown at the start.
LOOPscript.jstrueLeft alone, the demo’s pointer takes the sun to sunset, to night and to sunrise.

Try them in the Playground

When to use it

In a weather app, on a travel destination page, in the tool of a photographer looking for golden hour, on the page of a holiday home or a mountain hut; the same arc with an hour to drag carries a day’s tide, a plant’s shift, a day’s fast or a solar panel’s battery.

On phones

The card is at most 348 pixels wide and about 330 tall. The sky is 150 pixels tall or a third of the screen, whichever is less, and narrows with the card; with a finger the hour moves by dragging sideways, and the page still scrolls vertically.

With reduced motion

The sun appears already at the current hour, without climbing from sunrise; when dragging, sun, sky and texts jump to the chosen hour with no spring, and the pill changes in one step. The demo’s pointer does not start.

Pitfalls

  • The sky is a real slider: it has `role="slider"`, the value read as a time and the arrow keys; without them, those not using a pointer cannot move the sun.
  • The moment of the day is not told by the sky’s colour alone: the pill writes it and changes are announced to screen readers.
  • The arc is stretched with `preserveAspectRatio="none"`: strokes have `vector-effect: non-scaling-stroke`, and the sun and the times sit outside the svg, in percent, so they do not distort: a circle inside would turn into an oval.
  • The travelled stretch is drawn with `stroke-dashoffset` between 0 and 1: with GSAP’s pixel rounding it would jump from empty to full.
  • Times and city are made up for the demo: in a real app sunrise and sunset are worked out from date and place.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

Tested on 2 December 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