Skip to content

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.

Also known as: top products chart, leaderboard bar chart, sorted bar chart, ranking chart html, best selling products widget

Horizontal Bar Chart Ranking live demo

Open in new tab

Bootstrap 6 code (HTML, CSS, JS)

A horizontal bar chart ranking built with Bootstrap 6: a store's top 8 products with rank numbers, names, bars and values. A select switches the ranking between revenue, units sold and returns, and the rows glide into their new order. Use it as a leaderboard chart, a best sellers widget or a sorted bar chart on sales dashboards and admin panels.

How it works

The root .hbr-root holds a header with a Bootstrap 6 <select class="form-control">, a summary line, the .hbr-chart area and a footer note.

script.js reads the PRODUCTS array at the top of the file and builds one li.hbr-item per product inside the ol.hbr-list. Each row is a .hbr-row button with a .hbr-rank circle, the name and SKU, a .hbr-track with a .hbr-fill bar and the .hbr-value.

render() sorts the products by the selected metric, sets each bar width relative to the leader and colours it from the TINTS array (one indigo hue, darkest for rank 1). The rows are moved in the DOM, so reading order matches the visible order, and a FLIP animation slides them to their new place. The 30-day date range is computed from today.

Hovering, focusing or tapping a row shows the .hbr-tip tooltip with all three numbers for that product, including the return rate. A tap pins it (aria-expanded="true"); a second tap or Escape closes it.

Customization

  • PRODUCTS in script.js: replace names, SKUs and the revenue, units and returns numbers.
  • METRICS in script.js: rename a metric, change its number format, or add a new key together with an <option> in the select.
  • TINTS in script.js: a different colour ramp, for example teal or slate, from dark to light.
  • --hbr-accent, --hbr-track and --hbr-bg in style.css: rank circle colour, empty track colour and page background.
  • --hbr-row-gap on .hbr-root: more or less space between the bars.
  • grid-template-columns of .hbr-row in the 768px media query: wider name or value columns.

Use cases

  • E-commerce dashboards: best-selling products by revenue or units
  • Quality and support reports: products with the most returns at the top
  • Sales team leaderboards: reps ranked by deals or bookings
  • Content analytics: top pages or articles by views

Accessibility

The ranking is an ordered list labelled by the heading, and every row is a button that contains the rank, name and value as text; the bars are aria-hidden. The tooltip is linked with aria-describedby. When the metric changes, a polite live region announces the new top three and the biggest climber. A visually hidden table lists all products with all three numbers. Focus outlines are visible, and the row animation is switched off with prefers-reduced-motion.

Bootstrap 6 notes

Built on Bootstrap 6.0.0-alpha.1 (alpha APIs can still change). Bootstrap 6 has no separate select class: the select uses form-control inside a form-field. The leader chip uses badge badge-subtle theme-primary instead of badge bg-primary. The root has data-bs-theme="light" so it stays light in dark mode. Icons come from Bootstrap Icons.

Horizontal Bar Chart Ranking at a glance

Framework
Bootstrap 6
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Bootstrap 6, Bootstrap Icons
Layout
Responsive, works on mobile
Category
Charts
License
Free for personal and commercial use

Questions about this template

Can I use the Horizontal Bar Chart Ranking 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 Bootstrap 6 and Bootstrap Icons 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://cdn.jsdelivr.net/npm/bootstrap@6.0.0-alpha.1/dist/css/bootstrap.min.css">
  • <script type="module" src="https://cdn.jsdelivr.net/npm/bootstrap@6.0.0-alpha.1/dist/js/bootstrap.bundle.min.js"></script>
  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">

Built for Bootstrap 6.0.0-alpha.1. Bootstrap 6 ships as an ES module, so its script and this component's JavaScript load with type="module". Alpha releases can still change before the stable version.

Horizontal Bar Chart Ranking – free Bootstrap 6 chart template
Horizontal Bar Chart Ranking · free Bootstrap 6 chart template

More Charts

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.