Skip to content
animorio
IT
Back to the library

Stock chart crosshair

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

The card of a made-up stock, in the clean style of finance apps: the price line draws itself, a thin crosshair follows the pointer with its point on the line, the date and price tag arrives a moment later, the big price rolls digit by digit and the change turns green or red against the dashed starting line. 1D, 1W and 1M fold the line into the new one.

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>
<!--
  "Stock chart crosshair" 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 stock chart with a crosshair that follows the pointer</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>
    <!-- the card of a made-up stock, Ostrin Labs: the price line draws itself, a crosshair follows the pointer,
         the big price rolls to the value under it and the change turns green or red against the opening price -->
    <article class="card" data-card aria-label="Ostrin Labs stock">
      <header class="card__head">
        <div class="co">
          <span class="co__logo" aria-hidden="true">
            <svg viewBox="0 0 24 24"><path d="M12 3.5 19.4 8v8L12 20.5 4.6 16V8Z"/><path d="M12 3.5v17"/><path d="m4.6 8 7.4 4.3L19.4 8"/></svg>
          </span>
          <span class="co__text">
            <span class="co__name" data-name>Ostrin Labs</span>
            <span class="co__tick" data-ticker>OSTR</span>
          </span>
        </div>
        <div class="tabs" role="tablist" aria-label="Range">
          <span class="tabs__pill" data-pill aria-hidden="true"></span>
          <button class="tabs__tab is-on" type="button" role="tab" aria-selected="true" data-range="d">1D</button>
          <button class="tabs__tab" type="button" role="tab" aria-selected="false" data-range="w">1W</button>
          <button class="tabs__tab" type="button" role="tab" aria-selected="false" data-range="m">1M</button>
        </div>
      </header>

      <div class="quote">
        <div class="price" data-price aria-live="polite">
          <span class="price__cur">$</span><span class="price__digits" data-digits></span>
        </div>
        <div class="change" data-change>
          <svg class="change__tri" data-tri viewBox="0 0 10 10" aria-hidden="true"><path d="M5 2.2 8.6 7.6H1.4Z"/></svg>
          <span data-change-text>+0.00 (0.00%)</span>
          <span class="change__when" data-when>Today</span>
        </div>
      </div>

      <div class="chart" data-chart>
        <svg class="chart__svg" data-svg viewBox="0 0 400 170" preserveAspectRatio="none" aria-hidden="true">
          <defs>
            <linearGradient id="area-fill" x1="0" y1="0" x2="0" y2="1">
              <stop offset="0" stop-color="currentColor" stop-opacity="0.16"/>
              <stop offset="1" stop-color="currentColor" stop-opacity="0"/>
            </linearGradient>
            <clipPath id="lit"><rect data-lit x="0" y="-10" width="400" height="190"/></clipPath>
          </defs>
          <g class="chart__grid" data-grid></g>
          <line class="chart__open" data-open x1="0" x2="400" y1="80" y2="80"/>
          <path class="chart__dim" data-dim d=""/>
          <g clip-path="url(#lit)">
            <path class="chart__area" data-area d=""/>
            <path class="chart__line" data-line d=""/>
          </g>
          <g class="hair" data-hair>
            <line class="hair__v" data-hair-v x1="0" x2="0" y1="0" y2="170"/>
          </g>
        </svg>
        <span class="hair__dot" data-dot aria-hidden="true"></span>
        <div class="tag" data-tag aria-hidden="true">
          <span class="tag__price" data-tag-price>$0.00</span>
          <span class="tag__date" data-tag-date>9:30 AM</span>
        </div>
        <span class="chart__openlab" data-openlab>Open</span>
      </div>

      <dl class="stats">
        <div><dt>Open</dt><dd data-s-open>0</dd></div>
        <div><dt>High</dt><dd data-s-high>0</dd></div>
        <div><dt>Low</dt><dd data-s-low>0</dd></div>
        <div><dt>Volume</dt><dd data-s-vol>0</dd></div>
      </dl>
    </article>

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

34 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 “Stock chart crosshair” 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 very light grey background there is the white card of Ostrin Labs, a made-up company, with the ticker OSTR, the big price and the change of the day. On arrival the grid lines switch on, the dashed line of the opening price runs from left to right and the price line draws itself in green, with a gradient under it slowly rising; the big price rolls from zero to its value, digit by digit. Moving the pointer over the chart brings up a crosshair: a thin vertical line and a white-ringed point that always sits on the line. Left of the crosshair the line stays full and coloured, to the right it fades to grey. A black tag with price and time arrives a moment later and switches side near the edges. The big price rolls to the value under the crosshair and the change rewrites itself: green with the triangle up above the dashed line, red with the triangle turning over below it. When the crosshair passes over the high or the low, the figure below takes the colour and grows a little. Leave the chart and the whole line lights up again and the price goes back to the last one. The 1D, 1W, 1M pill slides on a spring and the line folds into the new week or month, together with the dashed line, while open, high, low and volume change. A drawn pointer reads the chart by itself, stops on the low and switches the range; it also works with a finger and the keyboard arrows.

How it works

The data

Each range has 64 made-up prices, built from a trend, a sine dip and a damped noise with a fixed-seed generator, so the chart is always the same. Each range has its own scale: the prices become coordinates of a 400 by 170 viewBox, with some air above and below.

The line and its dimmed half

The same line is drawn twice: below in grey, above in the state colour with the gradient, inside a clipPath. The clipPath rectangle is as wide as the crosshair’s x, interpolated by a value going from 0 to 1 when the crosshair enters, so the right part fades out and back in.

The crosshair and the late tag

The crosshair’s x is a number chased by gsap.quickTo in 0.12 seconds; on every frame GSAP’s ticker reads the y on the line by interpolating between the two nearest points and puts the point there. The tag has two quickTo of its own, slower (LAG), and switches side when it would touch the edge.

The rolling digits

The big price is made of five columns of digits from 0 to 9 under a faded mask. Each column has its own quickTo on yPercent: when the price under the crosshair changes by a cent, each one rolls to its digit, and while scrubbing the columns chase the value without stopping.

Switching the range

The white pill slides under the chosen tab with back.out. The line is not redrawn: a tween on a number from 0 to 1 interpolates every y from the old chart to the new one and rebuilds the path on every frame, and the dashed starting line does the same.

Values to change

NameFileDefaultWhat it changes
NAMEscript.js'Ostrin Labs'The name of the made-up company, top left.
TICKERscript.js'OSTR'The stock’s ticker, under the name.
OPEN_PRICEscript.js182.4Today’s opening price: the dashed line of the one-day chart.
UPscript.js'#0f9d6b'The colour when the price under the crosshair is above the starting one.
DOWNscript.js'#e0484d'The colour when the price under the crosshair is below the starting one.
LAGscript.js0.45The seconds the date and price tag takes to catch up with the crosshair.
MORPHscript.js0.8The seconds the line takes to fold into the new one when you switch 1D, 1W, 1M.
PAUSEscript.js1.1The seconds the autopilot rests on the points it shows.

Try them in the Playground

When to use it

For a finance or investing app, a dashboard with numbers changing over time, or a product page showing a trend: the chart is read with a finger and the big number always tells the value of the point you are looking at.

On phones

The same animation with adapted sizes: the card and the chart are sized on the width and the height, a finger dragged over the chart moves the crosshair like the pointer and the 1D, 1W, 1M tabs stay beside the name.

With reduced motion

The line is already there, without drawing itself; the crosshair and the tag follow at once without lag, the digits change without rolling and switching the range is a fade.

Pitfalls

  • With preserveAspectRatio none the chart stretches with the width, so the lines use vector-effect: non-scaling-stroke, and the point and the tag are HTML elements placed in pixels, not circles inside the SVG, which would turn into ovals.
  • The price only updates when it changes by a cent: calling the quickTo on every frame with the same value would restart them each time and the columns would never arrive.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

Compressed with gzip, the three demo files weigh 8.8 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 animations