Home / Trends Over Time / Candlestick Chart
Candlestick Chart in HTML, CSS and JavaScript
A candlestick chart shows four prices for each day: where the price opened, how high and low it went, and where it closed. This free template draws one with plain SVG and vanilla JavaScript, no chart library. The example shows daily share prices and volume for a made up robotics company.
What is a candlestick chart?
A candlestick chart shows four prices for each day: where the price opened, how high and low it went, and where it closed. The thick body runs from open to close, and the thin lines, called wicks, show the high and the low.
Green candles closed higher than they opened and red candles closed lower. Traders read runs of candles to see buying and selling pressure, and the volume bars below show how busy each day was.
At a glance
- Best for
- Prices that move within each day or period
- Data you need
- Open, high, low and close for each day, plus volume
- Skip it when
- Audiences who do not trade. A line chart is clearer.
- Made with
- HTML, CSS and vanilla JavaScript. No library.
When to use a candlestick chart
- Stock, fund and crypto prices
- Currency exchange rates
- Commodity prices like gold or oil
- Any price with a daily range
When to pick another chart
- Line Chart: you only need the closing price
- Step Line Chart: the price only changes now and then
What you get in this template
- Candles with bodies and wicks drawn in SVG
- Volume bars under the price in the same colors
- A crosshair showing open, high, low, close, change and volume
- A 30 day and 60 day switch
- The latest price marked on the right side
- Trading days only, with weekends skipped automatically
How the code works
Here is a short version of the idea behind this candlestick chart. The full file adds the axis, labels, tooltips, sorting and resizing on top of it.
const days = [[48.1, 49.0, 47.6, 48.8], [48.8, 49.5, 48.2, 48.4], [48.4, 50.2, 48.3, 50.0]];
const y = p => 280 - (p - 47) / 4 * 260;
days.forEach(([open, high, low, close], i) => {
const x = 60 + i * 40;
const color = close >= open ? '#2fbf8f' : '#f0506e';
drawLine(x, y(high), x, y(low), color, 1.5); // wick
drawRect(x - 10, y(Math.max(open, close)), 20,
Math.max(1, Math.abs(y(open) - y(close))), color); // body
});The example uses four tiny helpers that create SVG shapes. Put them above the code and it runs as is.
const svg = document.querySelector('svg');
function make(tag, attrs) {
const n = document.createElementNS('http://www.w3.org/2000/svg', tag);
for (const k in attrs) n.setAttribute(k, attrs[k]);
svg.appendChild(n);
return n;
}
function drawRect(x, y, width, height, fill) { return make('rect', { x, y, width, height, fill }); }
function drawCircle(cx, cy, r, fill) { return make('circle', { cx, cy, r, fill }); }
function drawLine(x1, y1, x2, y2, stroke, width, dash) {
return make('line', { x1, y1, x2, y2, stroke, 'stroke-width': width || 1, 'stroke-dasharray': dash || 'none' });
}
function drawText(x, y, str, anchor) {
const t = make('text', { x, y, 'text-anchor': anchor || 'start' });
t.textContent = str;
return t;
}How to add it to your website
- Download the file. Click Download HTML file above. You get one file called candlestick-chart.html with everything inside.
- Change the data. Open the file in any code editor and find the DATA list near the bottom. Replace the names and numbers with your own.
- Change the colors and text. Colors are at the top of the style tag. The title, subtitle and main point are plain HTML near the top of the body.
- Put it online. Upload the file to any host, such as GitHub Pages, Netlify or your own server, or paste it into your site. There is no build step.
Questions people ask
How do you read a candlestick chart?
Each candle is one day. The body shows the open and close price and the wicks show the high and low. Green means the price closed higher than it opened, red means it closed lower.
What is the difference between a candlestick chart and an OHLC chart?
They show the same four prices. An OHLC chart uses a line with small ticks for open and close, while a candlestick uses a filled body, which is easier to read at a glance.
Why are there gaps for weekends?
Markets are closed at weekends, so there are no candles for those days. This template skips weekends so the candles sit side by side.
Can I use this chart with live data?
Yes. Replace the ALL list with data from your own source in the same format: open, high, low, close and volume. Call the draw function again when new data arrives.
More trends over time

011. Line Chart
Example: new members each month for a yoga studio app
012. Multi Line Chart
Example: average home prices in three neighborhoods over ten years
013. Area Chart
Example: solar power made each day by a family home
014. Stacked Area Chart
Example: hours watched each month on a streaming app, by device
015. Streamgraph
Example: weekly listening hours by genre on a radio app
016. Step Line Chart
Example: the interest rate on a savings account from 2021 to 2026
017. Sparkline
Example: daily sales for six products in a shop dashboard
019. Slope Chart
Example: guest ratings for eight hotels in 2025 and 2026