Home / Dashboard Widgets / Timeline
Timeline in HTML, CSS and JavaScript
A timeline shows events in the order they happened, placed along a line by date. This free template draws one with plain SVG and vanilla JavaScript, no chart library. The example shows the history of a solar installer from 2014 to 2026.
What is a timeline?
A timeline shows events in the order they happened, placed along a line by date. Spacing the events by real time shows fast and slow periods, not just the order.
Timelines are perfect for company histories, project stories and personal milestones. Color by category helps readers pick out the kinds of events that matter to them.
At a glance
- Best for
- Events in date order
- Data you need
- A date, a title and a short note for each event
- Skip it when
- Lots of events on the same day. Group them.
- Made with
- HTML, CSS and vanilla JavaScript. No library.
When to use a timeline
- Company history and about pages
- Project milestones and launches
- Product release history
- Personal, school or family stories
When to pick another chart
- Gantt Chart: you show a plan with start and end dates
- Step Line Chart: you track a value that changes at each event
What you get in this template
- Events placed by real date along a line
- Cards above and below the line so they never overlap
- Colors for milestones, products and company news
- Tooltips with the full story of each event
- Turns into a top to bottom list on phones
- A table of every event with its details
How the code works
Here is a short version of the idea behind this timeline. The full file adds the axis, labels, tooltips, sorting and resizing on top of it.
const events = [[2014.2, 'Founded'], [2016.5, '100 homes'], [2021.7, '1,000 homes'], [2026.6, '5,000 homes']];
const x = year => 40 + (year - 2014) / 13 * 520, mid = 150;
drawLine(20, mid, 580, mid, '#e9e5d6', 5);
events.forEach(([year, title], i) => {
const up = i % 2 === 0, y = up ? mid - 60 : mid + 60;
drawLine(x(year), mid, x(year), y, '#e8a300', 2);
drawCircle(x(year), mid, 7, '#e8a300');
drawText(x(year), y + (up ? -6 : 16), title, 'middle');
});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 timeline.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 I make a timeline in HTML?
Draw a line, place a dot for each event at a position based on its date, and add a label above or below. This template does it in SVG with plain JavaScript.
Should events be spaced by date or evenly?
By date, when the gaps matter, like seven years to the first 1,000 installs. Even spacing is fine when only the order matters.
How do I stop timeline labels overlapping?
Alternate them above and below the line and vary the height of the connecting lines, like this template does.
How do I make a timeline work on a phone?
Switch to a vertical timeline that runs top to bottom, with text beside each dot. This template does that automatically below 640 pixels.
More dashboard widgets

061. Gauge Chart
Example: a hotel Net Promoter Score by quarter
062. Progress Ring Chart
Example: daily goals in a language learning app
063. KPI Cards with Sparklines
Example: revenue, orders, average order and returns for an online shop
064. Calendar Heatmap
Example: a year of code changes on an open source project
065. Gantt Chart
Example: a cafe renovation plan with tasks and milestones
066. Waterfall Chart
Example: how a bakery turns sales into profit
067. Word Cloud
Example: words guests use in hotel reviews
068. Pictogram Chart
Example: trees planted by a charity each year