A dark Bootstrap 5 segmented progress bar that splits one bar into colored parts for several values, with an interactive legend. Typical uses are storage usage meters, sprint or task status overviews, budget breakdowns and quota displays in dashboards.
How it works
Each .sp-card contains a Bootstrap .progress-stacked bar (.sp-bar) and a legend (.sp-legend). Every segment is a .progress element with role="progressbar", an aria-label, a data-sp-key and a data-sp-value. The card's data-sp-total sets what 100% means and data-sp-unit the unit shown in texts.
On DOMContentLoaded the script reads each value, calculates its percentage of the total and sets aria-valuenow, aria-valuemax and a readable aria-valuetext. It fills the matching legend .sp-pct with the percentage, writes the summed value into .sp-used and the remaining share into .sp-pct--rest. Then it adds .sp-ready and grows every segment from 0 to its width with a CSS transition. A Bootstrap tooltip on each segment shows the label, value and percentage on hover.
Legend entries are buttons. Hovering or focusing one adds .sp-card--focus to the card, which fades every segment except the matching .is-active one. Clicking a legend button pins that highlight and sets aria-pressed="true"; clicking it again releases it. The second card uses .sp-bar--gapped, which adds gaps, padding and rounded segments for a block-style look.
Customization
data-sp-totalanddata-sp-uniton.sp-card: set the maximum and the unit, for example100and%.data-sp-valueon each.progress: change a segment's size; percentages and ARIA values are recalculated.--sp-c1to--sp-c5on.sp-section: change the segment colors used by the.sp-c1to.sp-c5classes.--sp-heighton.sp-sectionor.sp-bar--gapped: makes the bar thinner or taller.- Add or remove
.sp-bar--gappedon.sp-bar: switch between a continuous bar and separated blocks. progress-bar-stripedon a.progress-bar: marks a segment as in progress with diagonal stripes.--sp-cardand--sp-trackon.sp-section: recolor the cards and the unused part of the bar.
Use cases
- Storage dashboards: one bar splits usage into colored segments for files, photos and other data
- Budget and analytics pages: tooltips and percentages explain each part of a total
- Admin panels: a legend highlights the matching segment on hover
- Reports: stacked segments show how a whole breaks down in a small space
Accessibility
Each segment is a separate role="progressbar" with its own label and an aria-valuetext such as "Photos: 92 GB (35.9%)". Legend buttons are keyboard focusable, show a visible outline and report their pinned state with aria-pressed. Color is never the only cue because each legend entry repeats the name, value and percentage in text. The width transition and stripe animation are disabled for prefers-reduced-motion.
Usage notes
Requires Bootstrap 5.3 (for .progress-stacked, added automatically) and Bootstrap Icons. Without JavaScript the segments share the bar equally, so keep the script enabled. Several cards work independently on one page.