Skip to content

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.

Also known as: svg pie chart, budget breakdown chart, pie chart with legend, percentage pie chart, expense chart html

Pie Chart with Percentage Legend live demo

Open in new tab

Bootstrap 6 code (HTML, CSS, JS)

A budget pie chart built with Bootstrap 6 and plain SVG: six spending categories, a legend table with amount and percent, and a slice that pulls out when you pick it. Use this pie chart template as an expense breakdown, a budget planner widget or a percentage chart in finance apps and reports.

How it works

The root .bpc-root holds a Bootstrap 6 .card with a header, a figure with the pie and a .bpc-legend table. script.js reads the BUDGET array, draws one SVG path per item inside .bpc-slices (percent labels on slices of 6% or more) and builds a table row with a .bpc-toggle button, the amount (Intl.NumberFormat), the share and a small share bar. Percentages use the largest remainder method, so they always add up to exactly 100%.

Clicking a slice or a row calls select(): the slice gets .is-active and moves out along its middle angle (PULL), the others get .is-dim, and the row button gets aria-pressed="true". The .bpc-detail pill shows the category, amount and share. Clicking again or pressing Escape puts the slice back. Hovering a slice or row, or focusing a row button, shows the .bpc-tip tooltip. On load the largest category is pulled out.

Customization

  • BUDGET in script.js: replace the labels, amounts and color values; the pie, table and total update on their own.
  • CURRENCY in script.js: switch to EUR, GBP or any ISO code for every amount.
  • PULL and RADIUS in script.js: how far the selected slice moves out and how large the pie is.
  • --bpc-pie-size on .bpc-root: the pie width and the left column width on wide screens.
  • --bpc-bg, --bpc-card, --bpc-line and --bpc-active in style.css: page background, card surface, table lines and the selected row tint.
  • Remove the .bpc-bar span in script.js to show only the percent number in the Share column.

Use cases

  • Personal finance apps: show how a monthly budget is split across categories
  • Accounting and expense dashboards: compare cost centres by share of the total
  • Survey and poll results: show answer shares with exact percentages

Accessibility

The SVG has role="img" and a title that lists every category with its percent; the slices are hidden from screen readers. The legend is a real table with a hidden caption and a total row, so the same numbers are available as text. Every category is a native button with aria-pressed, operated with Tab, Enter or Space; focus shows the tooltip and an outline. The detail pill is an aria-live="polite" region, so each selection is announced. Names and percents are always written out, so color is never the only cue. Slice movement uses a short transition that is switched off with prefers-reduced-motion.

Bootstrap 6 notes

Built on Bootstrap 6.0.0-alpha.1 (alpha APIs can still change). It uses .card and .table, with --bs-table-bg and --bs-card-bg set on the component. The root has data-bs-theme="light", so it keeps its light look when the visitor uses dark mode. Icons come from Bootstrap Icons.

Pie Chart with Percentage Legend 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 Pie Chart with Percentage Legend 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.

Pie Chart with Percentage Legend – free Bootstrap 6 chart template
Pie Chart with Percentage Legend · free Bootstrap 6 chart template

More Charts

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.