Skip to content

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.

Also known as: monthly sales bar chart, column chart with tooltips, vertical bar graph, bar chart without library, revenue bar chart

Bar Chart with Axis and Tooltips live demo

Open in new tab

Pure CSS code (HTML, CSS, JS)

A monthly sales bar chart built with pure CSS and a few lines of vanilla JavaScript, no chart library needed. This column chart example has a labelled value axis with gridlines, a tooltip on every bar and a this year / last year toggle for sales dashboards, revenue reports and admin panels.

How it works

The root section.bc-chart holds a header with a segmented control (.bc-toggle, two native radio buttons), a row of summary figures (.bc-stats) and the chart itself. .bc-yaxis carries the value labels, .bc-grid the gridlines and ul.bc-bars the twelve bars in a CSS grid.

All numbers live in the DATA object at the top of script.js: labels, full month names and two series, current and previous. On DOMContentLoaded the script picks a "nice" axis maximum with niceStep() (both series share one scale, so switching years stays honest), draws the axis labels and gridlines, and builds one button.bc-bar per month. Each bar height is set through the --bc-h custom property as a percentage of the plot.

Hovering with a mouse, focusing with the keyboard or tapping a bar adds .is-active, which shows its .bc-tip tooltip with the exact value and the change against the other year. The highest month is active on load. Changing the radio button re-renders the heights, totals and best month, and .bc-fill animates to the new height. The class is-ready is added only after the first paint, so the chart is drawn at once and animates only on later changes.

Customization

  • DATA.series in script.js: replace values with your own figures; labels, totals, tooltips and the table update automatically.
  • DATA.currency: any ISO code such as EUR or GBP; all amounts are formatted with Intl.NumberFormat.
  • DATA.ticks: roughly how many gridlines the value axis gets (default 5).
  • --bc-bar, --bc-bar-top and --bc-bar-active on .bc-chart: the indigo bar gradient and the highlighted bar color.
  • --bc-plot-h: plot height, 15rem on phones and 17.5rem from 640px.
  • width: min(62%, 2.5rem) in .bc-fill: make bars wider or slimmer.
  • --bc-tip-bg: the dark tooltip background.

Use cases

  • E-commerce dashboards: compare monthly sales with the previous year at a glance.
  • SaaS revenue reports: show monthly recurring revenue with exact values on hover.
  • Admin panels: a compact, library-free chart for any twelve-month metric.
  • Annual reports and landing pages: present growth figures in a clean, readable card.

Accessibility

Each bar is a real button with an aria-label such as "March, this year: $47,900, +19.2% compared with last year", so screen readers and keyboard users get the value without the tooltip. Arrow keys, Home and End move between bars, and focus is clearly outlined. The radio buttons are grouped in a fieldset with a hidden legend. A visually hidden table.bc-sr lists every month for both years, and a polite live region announces the new total when the year changes. Reduced motion disables the animation.

Usage notes

Several charts can share a page; the script gives each radio group a unique name.

Bar Chart with Axis and Tooltips 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 Bar Chart with Axis and Tooltips 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=Inter:wght@400;500;600;700&display=swap">
Bar Chart with Axis and Tooltips – free Pure CSS chart template
Bar Chart with Axis and Tooltips · free Pure CSS chart template

More Charts

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.