Skip to content
animorio
IT
Back to the library

Candlestick chart

SVG, HoverGSAP, CSS onlyAdvancedCompressed weight: Demo 9.5 KBGSAP 28 KBFreeDownload the zip

The candlestick chart of a trading app, in SVG: the candles grow one after the other from the left, the crosshair snaps on a spring to the nearest candle and reads its open, high, low and close, while the others step back. The last candle keeps moving with the price, like an open market, and on a new range (a day, a week, a month, three months) every candle travels to its new size along with the scale.

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>
<!--
  "Candlestick 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>Candlestick chart</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 candlestick chart of a trading app: the candles grow one after the other, the crosshair
         reads open, high, low and close, the last candle keeps ticking and the ranges reshape them all -->
    <section class="cs" data-cs aria-label="Candlestick chart of Novalo Systems">
      <header class="cs__top">
        <span class="cs__mark" aria-hidden="true"><svg viewBox="0 0 20 20"><path d="M5.500 14.500v-9l9 9v-9"></path></svg></span>
        <span class="cs__id"><b>NVLO</b><span>Novalo Systems</span></span>
        <span class="cs__quote"><strong data-outprice>184.62</strong><span class="cs__chg" data-chg><svg viewBox="0 0 10 8" aria-hidden="true"><path d="M5 1 9 7H1Z"></path></svg><span class="cs__chgtext"><b data-outchg>+1.84%</b></span></span></span>
      </header>
      <div class="cs__read" data-read>
        <span>O <b data-outo>0.00</b></span><span>H <b data-outh>0.00</b></span><span>L <b data-outl>0.00</b></span><span>C <b data-outc>0.00</b></span>
        <span class="cs__when" data-outwhen>Now</span>
      </div>
      <div class="cs__plot" data-plot tabindex="0" role="img" aria-label="Price candles. Use the left and right arrows to read each candle.">
        <svg data-svg aria-hidden="true">
          <g data-grid></g>
          <g data-vol></g>
          <g data-candles></g>
          <line class="cs__lastline" data-lastline></line>
          <line class="cs__cross" data-vx></line>
          <line class="cs__cross" data-hy></line>
        </svg>
        <span class="cs__ylab" data-ylab></span><span class="cs__ylab" data-ylab></span><span class="cs__ylab" data-ylab></span>
        <span class="cs__tag cs__tag--last" data-lasttag>184.62</span>
        <span class="cs__tag cs__tag--y" data-ytag>0.00</span>
      </div>
      <div class="cs__axis" data-axis aria-hidden="true"><span data-xlab></span><span data-xlab></span><span data-xlab></span></div>
      <div class="cs__frames" role="group" aria-label="Time range" data-frames>
        <span class="cs__thumb" data-thumb aria-hidden="true"></span>
        <button type="button" data-frame="1D" aria-pressed="true">1D</button>
        <button type="button" data-frame="1W" aria-pressed="false">1W</button>
        <button type="button" data-frame="1M" aria-pressed="false">1M</button>
        <button type="button" data-frame="3M" aria-pressed="false">3M</button>
      </div>
    </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.

31 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 “Candlestick 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 black, a dark card with a green glint in one corner: at the top the mark, the ticker NVLO and the name of the invented company, on the right the price and the change with its arrow; below, the row with open, high, low and close; then the chart, with three dashed scale lines, the candles green when they rise and grey when they fall, the volume bars at the bottom and the dotted line of the last price with its tag; at the bottom the range selector: 1D, 1W, 1M, 3M. On opening the candles grow from the middle of their body, one after the other from the left, on a small bounce. Moving over the chart brings in the crosshair: the upright line snaps on a spring to the nearest candle, the level one follows the pointer with the price tag on the scale; the candle being read widens and lights up, the others dim, and the row above writes its four prices and the time or the day. The last candle keeps moving: its body stretches and shrinks, the price above changes with a flash of colour and the last price line follows. On a new range the pill slides under the chosen label, every candle travels to its new shape a little after the one before, the scale and the dates update and the change rolls over, turning its arrow when it is negative. It also reads from the keyboard, with the left and right arrows.

How it works

The data of every range

Every range is a random walk with a fixed seed: for each candle an open, a high, a low, a close and a volume. At the end the series is shifted so that its last close is the price right now, so all the ranges end at the same point.

One drawing for everything

GSAP does not move the SVG elements: it moves numbers (the prices of every candle, the scale, the position of the crosshair). A single function redraws rectangles and lines from those numbers, once a frame and only if something changed.

The snapping crosshair

The nearest candle is worked out from the pointer’s position. The upright line goes to its centre on a spring, the level one follows the pointer and the tag’s price is read backwards from the scale.

Changing the range

The candles are always the same ones: each is given its new target and goes there a little after its neighbour, while the bottom and the top of the scale move along.

Values to change

NameFileDefaultWhat it changes
ACCENTscript.js#2fd08aThe colour of the rising candles, the change and the mark.
CANDLESscript.js26How many candles the chart has.
SWINGscript.js1How wide the price swings are.
SPRINGscript.js1How much the candles, the crosshair and the selector bounce.

Try them in the Playground

When to use it

On the page of a stock or a coin in a trading, investing or crypto app; on a broker’s landing page, as a product piece that really moves; in a dashboard where a price has to be read over time, not just as a line.

On phones

The card is at most 344 pixels wide and narrows with the screen: the candles get thinner but all stay. The chart is at most 188 pixels tall and gets shorter on short screens. With a finger the crosshair moves by dragging sideways, and the page still scrolls vertically.

With reduced motion

The candles are in place at once and the last one stays still. The crosshair appears on the candle without a spring, a new range redraws the chart at once and the change switches without rolling. The demo’s pointer does not start.

Pitfalls

  • Rising and falling are not told by colour alone: the row above writes the four prices, and from the keyboard every candle is announced in an aria-live region.
  • Animating the attributes of dozens of SVG rectangles one by one with GSAP is costly and gets the pivots wrong: here the numbers are animated and a single drawing reads them.
  • The viewBox is taken from the pixel size of the plot: when the window changes width it is measured and redrawn, or the candles get distorted.
  • Prices, company and volumes are invented and generated from a seed: in a real product they come from the server, and the last candle updates with live data.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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