Skip to content

SVG Line Chart with Hover Points

Smooth SVG line chart of daily website visitors with a gradient area fill, axis labels, and a crosshair tooltip that follows the pointer or the arrow keys.

Also known as: line graph with tooltip, svg area chart, website traffic chart, line chart crosshair, time series chart

SVG Line Chart with Hover Points live demo

Open in new tab

Pure CSS code (HTML, CSS, JS)

A smooth SVG line chart with hover points, built with pure CSS and vanilla JavaScript and no chart library. This area chart example plots daily website visitors for the last 30 days with a gradient fill, axis labels and a crosshair tooltip for analytics dashboards, SaaS admin panels and traffic reports.

How it works

The root section.lc-card has a header with three figures (.lc-kpis), the focusable plot .lc-plot with an empty svg.lc-svg, an HTML tooltip .lc-tip and a visually hidden table.

The numbers come from DATA.values at the top of script.js, one value per day with the last value being today. Dates are computed from today and shown without a year, so the chart never looks out of date. draw() measures the plot, sets the SVG viewBox to its real pixel size and builds the gridlines, value labels (niceStep() picks round steps), weekly date labels, the .lc-area fill with a linearGradient and the .lc-path line. smoothPath() uses monotone cubic interpolation, so the curve is smooth but never overshoots the data.

select() moves the dashed .lc-cross line, the .lc-dot point and the tooltip to a day. Pointer movement over the plot picks the nearest day, and on touch screens a horizontal drag does the same while vertical scrolling still works (touch-action: pan-y). The tooltip shows the date, the value and the change against the previous day, flips to the left near the right edge and is placed above or below the line so it does not hide it. Today is selected on load. On window resize the chart is redrawn at the new width.

Customization

  • DATA.values in script.js: your own daily numbers, oldest first; KPIs, labels and table update automatically.
  • DATA.unit: the word after each value, e.g. orders or sign-ups.
  • DATA.ticks: approximate number of gridlines on the value axis.
  • --lc-line and --lc-fill on .lc-card: the line colour and the colour of the gradient area.
  • --lc-height: chart height, 16rem on phones and 20rem from 760px.
  • PAD in script.js: inner spacing for the axis labels.
  • stroke-width in .lc-path: a thinner or bolder line.

Use cases

  • Website analytics: daily visitors, page views or sessions over the last month.
  • SaaS dashboards: sign-ups or active users with the exact value per day.
  • E-commerce reports: daily orders or revenue trends.
  • Status and monitoring pages: requests or response times over time.

Accessibility

The plot is a role="slider" with aria-valuenow, aria-valuemax and an aria-valuetext such as "Tue, Nov 18: 1,502 visitors", so screen readers announce each day. Left and Right arrows move one day, Page Up and Page Down a week, Home and End jump to the first and last day, and the focus ring is clearly visible. The SVG and tooltip are aria-hidden; a visually hidden table.lc-sr lists all 30 dates and values.

Usage notes

Several charts can share a page; each one gets its own gradient id.

SVG Line Chart with Hover Points at a glance

Framework
Pure CSS
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
fonts.googleapis.com
Layout
Responsive, works on mobile
Category
Charts
License
Free for personal and commercial use

Questions about this template

Can I use the SVG Line Chart with Hover Points code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

Load fonts.googleapis.com from a CDN (the links are under Requirements). Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

Add these to your page (already included in the download):

  • <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=DM+Sans:opsz,wght@9..40,400;9..40,500;9..40,600;9..40,700&display=swap">
SVG Line Chart with Hover Points – free Pure CSS chart template
SVG Line Chart with Hover Points · free Pure CSS chart template

More Charts

Multi-Line Chart with Range Tabs – free Bootstrap 6 chart template

Multi-Line Chart with Range Tabs

SVG multi-line chart comparing organic, paid and email traffic, with 7 day, 30 day and 12 month tabs, legend toggles and a crosshair tooltip.

Sparkline KPI Row – free Pure CSS chart template

Sparkline KPI Row

Sparkline KPI row with four stat tiles, change badges and SVG sparklines that redraw when a 7d, 30d or 90d range is picked, with keyboard and touch tooltips.

Horizontal Bar Chart Ranking – free Bootstrap 6 chart template

Horizontal Bar Chart Ranking

Horizontal bar chart ranking the top 8 products by revenue, units or returns; a select re-sorts the bars and announces the new order.

Donut Chart with Legend – free Pure CSS chart template

Donut Chart with Legend

SVG donut chart of traffic sources with the total in the centre and an interactive legend that highlights each segment and shows its share, value and percent.

Pie Chart with Percentage Legend – free Bootstrap 6 chart template

Pie Chart with Percentage Legend

Budget pie chart with a percentage legend table: SVG slices drawn from a data array, and clicking a slice or category row pulls the slice out.

Bar Chart with Axis and Tooltips – free Pure CSS chart template

Bar Chart with Axis and Tooltips

Monthly sales bar chart with a labelled value axis, gridlines, tooltips on hover, focus and tap, and a this year / last year toggle that animates the bars.