Skip to content
animorio
IT
Back to the library

Daily UV index

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

The day’s UV index on a card: a sun travels along the curve of the hours and takes the figure, the level, the colour and the advice with it; moving over the chart picks the hour, and the bar on the axis marks the hours when protection is needed.

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>
<!--
  "Daily UV index" 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>Daily UV index</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 day's UV index: a sun travels along the curve of the hours, the figure, the level and the advice
         follow it, and the bar on the axis marks the hours in which protection is needed -->
    <section class="uv" data-uv aria-label="UV index today">
      <header class="uv__head">
        <span class="uv__title">UV index</span>
        <span class="uv__place">Cala Brisa, <span data-time>12:00</span></span>
      </header>

      <p class="uv__read" aria-live="polite">
        <b class="uv__num" data-num>0</b>
        <span class="uv__level"><span data-level></span></span>
      </p>

      <svg class="uv__chart" data-chart viewBox="0 0 300 128" role="img" aria-label="UV index through the day">
        <defs>
          <linearGradient id="uv-fill" x1="0" y1="0" x2="0" y2="1">
            <stop offset="0" stop-color="currentColor" stop-opacity="0.26"></stop>
            <stop offset="1" stop-color="currentColor" stop-opacity="0"></stop>
          </linearGradient>
          <clipPath id="uv-past"><rect data-past x="0" y="0" width="0" height="128"></rect></clipPath>
        </defs>
        <line class="uv__three" data-three x1="12" x2="288" y1="78" y2="78"></line>
        <path class="uv__area" data-area fill="url(#uv-fill)" clip-path="url(#uv-past)"></path>
        <path class="uv__curve uv__curve--day" data-day pathLength="1"></path>
        <path class="uv__curve uv__curve--past" data-curve clip-path="url(#uv-past)"></path>
        <line class="uv__hair" data-hair x1="0" x2="0" y1="6" y2="100"></line>
        <line class="uv__base" x1="12" x2="288" y1="100" y2="100"></line>
        <g data-ticks></g>
        <line class="uv__protect" data-protect x1="0" x2="0" y1="108.5" y2="108.5"></line>
        <g class="uv__sun" data-sun>
          <circle class="uv__halo" data-halo r="12"></circle>
          <g data-rays></g>
          <circle class="uv__core" r="5"></circle>
        </g>
      </svg>

      <footer class="uv__foot">
        <span class="uv__advice"><span data-advice></span></span>
        <span class="uv__window" data-window></span>
      </footer>
    </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.

15 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 “Daily UV index” 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 warm white ground, a card: at the top “UV index” with the place and the time; below, the large index figure in its level’s colour and the level’s name; then the day’s chart, a bell curve from sunrise to sunset with a dashed line at the height of 3, and on the hour axis a thick bar covering the hours in which the index is 3 or more; at the bottom the advice and “Protect 9:10 to 17:50”. On opening the curve is drawn, the bar grows from the left and a small sun climbs along the curve to the present hour, leaving the solid curve and the shaded area behind it. Moving over the chart, the sun follows the pointer: the figure changes and gets heavier towards midday, the rays grow longer, the hour ticks rise beneath it, and when the level changes the colour blends and name and advice roll. On leaving, the sun goes back to the present hour by itself.

How it works

A single number, the hour

Everything comes from the hour: the index is a bell function between sunrise and sunset, and from it come the sun’s position, the width of the clip that uncovers the solid curve and the area, the figure’s weight on the wght axis, the length of the rays.

The level as a variable

When the rounded index changes level, a CSS variable takes the new colour: figure, curve, sun, bar and the light inside the card read it and blend with a transition. Name and advice roll in the direction of the change.

The sun in attributes

The sun is an SVG group drawn around zero: its position goes into the group’s transform attribute, the slow turn of the rays into the inner group’s, so the rotation is always about its centre.

Values to change

NameFileDefaultWhat it changes
PEAKscript.js9The day’s highest UV index, at midday.
NOWscript.js16.5The present time, in decimal hours (16.5 = 16:30).
SUNRISEscript.js6.6The time of sunrise.
SUNSETscript.js20.4The time of sunset.
GLIDEscript.js0.9How many seconds the sun takes to go back to the present hour.
LOOPscript.jstrueLeft alone, a pointer travels through the day.

Try them in the Playground

When to use it

In a weather app, on the site of a beach club, a seaside hotel or a mountain hut, on a sunscreen’s page; and wherever a value changes through the day and is read at a given hour: the tide, the energy price, how busy a place is.

On phones

The same card: a finger on the chart picks the hour (the page still scrolls vertically) and shortly after lifting it the sun goes back to now. The figure and the chart shrink with the window’s height.

With reduced motion

No curve drawing, spinning or rolling: the sun already sits on the present hour and, moving over the chart, figure, level and advice change at once.

Pitfalls

  • The demo’s curve is made up (a bell between sunrise and sunset): real index values come from a weather service, hour by hour, and depend on clouds, altitude and season.
  • The five levels and the threshold of 3 follow the World Health Organization scale; the advice is cut down to a few words and does not replace a doctor’s guidance.
  • The level is not told by colour alone: the name is always beside the figure, and figure and level sit in an aria-live line.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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