Skip to content
animorio
IT
All components

Sleep phases chart

Charts, HoverGSAP, CSS onlyMediumCompressed weight: Demo 6.5 KBGSAP 28 KBFreeDownload the zip

The night card of a wellness app, on near black and in a single colour in four tones: the stepped hypnogram draws itself from the left, the score ring fills and the phase durations roll up. Dragging a finger across the chart, a line reads the time and the phase, the label follows a beat behind and the phase lights up in the legend and the list.

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>
<!--
  "Sleep phases chart" 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 sleep chart with phases to scrub through</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>
    <!-- last night's sleep in a wellness app: the hypnogram draws itself step by step, a finger dragged across it
         reads the time and the phase, the phase lights up in the legend and in the list, the score fills its ring -->
    <section class="sleep" data-card aria-label="Nightfern, last night's sleep">
      <header class="sleep__head">
        <div class="sleep__title">
          <svg class="sleep__mark" viewBox="0 0 24 24" aria-hidden="true"><path d="M15.5 3.6a8.6 8.6 0 1 0 4.9 13.6A7.2 7.2 0 0 1 15.5 3.6Z"/></svg>
          <div>
            <p class="sleep__brand">Nightfern</p>
            <p class="sleep__night">Last night · Tue 27</p>
          </div>
        </div>
        <div class="score" aria-label="Sleep score">
          <svg class="score__ring" viewBox="0 0 52 52" aria-hidden="true">
            <circle class="score__track" cx="26" cy="26" r="22"/>
            <circle class="score__fill" cx="26" cy="26" r="22" data-ring/>
          </svg>
          <span class="score__num" data-score>0</span>
        </div>
      </header>

      <div class="chart" data-chart>
        <svg class="chart__svg" viewBox="0 0 320 128" aria-hidden="true" data-svg>
          <g class="chart__rows" data-rows></g>
          <g class="chart__links" data-links></g>
          <g class="chart__steps" data-steps></g>
          <g class="chart__axis" data-axis></g>
          <line class="chart__cursor" x1="0" y1="2" x2="0" y2="110" data-cursor/>
          <circle class="chart__knob" cx="0" cy="0" r="3.4" data-knob/>
        </svg>
        <div class="tip" data-tip><span class="tip__time" data-tip-time>02:14</span><span class="tip__phase" data-tip-phase>Deep</span></div>
        <p class="chart__hint" data-hint>Drag across the night</p>
      </div>

      <ul class="phases" data-phases></ul>

      <footer class="sleep__foot">
        <span>Time asleep</span>
        <strong data-asleep>0h 00m</strong>
      </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"/></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.

24 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 “Sleep phases chart” 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 near-black background sits the card of Nightfern, an invented wellness app: the moon as its mark, «Last night · Tue 27» and on the right the score ring filling up to 84 as the number climbs. Below, the hypnogram of the night from 23:10 to 07:05 on four rows, Awake, REM, Light and Deep, each in its own tone of the same violet, lighter when awake and darker in deep sleep: the steps draw themselves from the left one after another and the thin lines joining them appear just after. Under the chart, the four phases with a thin bar and the duration rolling up, and at the bottom the time asleep, 7h 17m. Dragging a finger across the chart (or hovering with the mouse) a dotted line follows the hand, a small knob settles on the step of that moment, a dark label with the time and the phase follows a beat behind, and the phase lights up in the legend and the list, its bar gives a little jolt and the steps of the other phases dim. A drawn pointer scrubs through the night by itself, stops on the phases and starts again.

How it works

The night as a list of phases

The night is a list of phases with their minutes, scaled to the 475 minutes between 23:10 and 07:05: each phase becomes a rounded rectangle six units tall on its row, and between one rectangle and the next a thin vertical line makes the step.

Steps that draw themselves

On arrival the rectangles start at scaleX 0 with the origin on the left and stretch one after another with a stagger that divides DRAW_TIME by their number; the step lines appear at the same pace, a little later.

From finger to time

The finger’s x is turned into viewBox coordinates, then into minutes: the phase that holds them is found, the dotted line and the knob move there and the label follows with gsap.quickTo, which gives it the soft delay.

A phase lit up

When the phase changes, its name in the legend and its row in the list take the full colour, its bar gives a jolt in height with back.out and the rectangles of the other phases drop to 35% opacity.

Values to change

NameFileDefaultWhat it changes
APPscript.jsNightfernThe name of the invented wellness app.
SCOREscript.js84The sleep score that fills the ring.
ACCENTscript.js#8f91ffThe colour of the phases, in four tones, and of the ring.
DRAW_TIMEscript.js1.6The seconds the hypnogram takes to draw itself.
LAGscript.js0.35The seconds the label takes to catch up with the finger.
PAUSEscript.js1.2The seconds the autopilot rests on a phase.

Try them in the Playground

When to use it

For a wellness or sports app, the data page of a smart ring or watch, a health dashboard, anywhere a night or a day is read hour by hour.

On phones

The card takes almost the whole width and the chart scales with it thanks to the viewBox; under 380 pixels the list tightens. A dragged finger does what the mouse does.

With reduced motion

The chart, the ring and the durations are already in place, without drawing; when dragging, the line and the label jump straight to the point, with no delay or jolts, and the drawn pointer is absent.

Pitfalls

  • The finger must be brought into viewBox coordinates with the SVG’s real width on every move: the card changes size on the phone and with the viewer’s safety net.
  • The label follows with quickTo but its x must stay inside the chart’s width, or at both ends of the night it leaves the card.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

Tested on 27 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 components