Component Library

← Back to gallery

Meter gauge with allocation breakdown in HTML, CSS and vanilla JS

A copy-paste Meter gauge with allocation breakdown in plain HTML and CSS, with vanilla JavaScript: no framework, no build step, MIT-licensed.

Category: Data display · Tags: meter, data-display, responsive

Live preview

Source (copy-ready)

<div class="dcl-meter-gauge-stacked-capacity" data-dcl-scheme="light">
<header><p class="dcl-meter-gauge-stacked-capacity-eyebrow">MONTHLY QUOTA</p><h3>Studio storage</h3></header><meter aria-label="Studio storage used in gigabytes" min="0" max="100" value="78" >78</meter><div class="dcl-meter-gauge-stacked-capacity-allocation" aria-hidden="true"><span></span><span></span><span></span></div><dl class="dcl-meter-gauge-stacked-capacity-grid"><div><dt>Archive</dt><dd>50 GB</dd></div><div><dt>Active work</dt><dd>28 GB</dd></div><div><dt>Available</dt><dd>22 GB</dd></div></dl>
<script>
(() => {
  const root = document.currentScript.closest(".dcl-meter-gauge-stacked-capacity");
  const preference = matchMedia("(prefers-color-scheme: dark)");
  function setScheme() { root.dataset.dclScheme = preference.matches ? "dark" : "light"; }
  preference.addEventListener("change", setScheme);
  setScheme();
})();
</script>
</div>
<style>
.dcl-meter-gauge-stacked-capacity, .dcl-meter-gauge-stacked-capacity * { box-sizing: border-box; }
.dcl-meter-gauge-stacked-capacity { max-inline-size: 44rem; margin-inline: auto; padding: clamp(.875rem, 4vw, 1.5rem); border: 1px solid; border-radius: .75rem; font: 1rem/1.5 system-ui, sans-serif; overflow-wrap: anywhere; }
.dcl-meter-gauge-stacked-capacity h3, .dcl-meter-gauge-stacked-capacity h4, .dcl-meter-gauge-stacked-capacity p, .dcl-meter-gauge-stacked-capacity figure, .dcl-meter-gauge-stacked-capacity dl, .dcl-meter-gauge-stacked-capacity ul, .dcl-meter-gauge-stacked-capacity ol { margin: 0; }
.dcl-meter-gauge-stacked-capacity h3 { font-size: 1.18rem; line-height: 1.25; }
.dcl-meter-gauge-stacked-capacity header { margin-block-end: .875rem; }
.dcl-meter-gauge-stacked-capacity .dcl-meter-gauge-stacked-capacity-eyebrow { font-size: .8125rem; font-weight: 700; letter-spacing: .06em; }
.dcl-meter-gauge-stacked-capacity .dcl-meter-gauge-stacked-capacity-well { padding: .7rem .8rem; border: 1px solid; border-radius: .55rem; }
.dcl-meter-gauge-stacked-capacity .dcl-meter-gauge-stacked-capacity-muted { font-size: .875rem; }
.dcl-meter-gauge-stacked-capacity .dcl-meter-gauge-stacked-capacity-row { display: flex; gap: .55rem .8rem; align-items: center; flex-wrap: wrap; }
.dcl-meter-gauge-stacked-capacity .dcl-meter-gauge-stacked-capacity-grid { display: grid; gap: .65rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr)); }
.dcl-meter-gauge-stacked-capacity dt { font-size: .875rem; font-weight: 650; }
.dcl-meter-gauge-stacked-capacity dd { margin: 0; }
.dcl-meter-gauge-stacked-capacity .dcl-meter-gauge-stacked-capacity-value { font-size: clamp(1.35rem, 5vw, 1.9rem); font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1.2; }
.dcl-meter-gauge-stacked-capacity button, .dcl-meter-gauge-stacked-capacity summary, .dcl-meter-gauge-stacked-capacity input { font: inherit; }
.dcl-meter-gauge-stacked-capacity button, .dcl-meter-gauge-stacked-capacity summary { min-height: 2.75rem; cursor: pointer; }
.dcl-meter-gauge-stacked-capacity button { padding: .35rem .7rem; border: 1px solid; border-radius: .4rem; }
.dcl-meter-gauge-stacked-capacity button:active { transform: translateY(1px); }
.dcl-meter-gauge-stacked-capacity button:disabled { cursor: default; border-style: dashed; }
.dcl-meter-gauge-stacked-capacity [hidden] { display: none; }
.dcl-meter-gauge-stacked-capacity meter { display:block; inline-size:100%; block-size:1.4rem; }.dcl-meter-gauge-stacked-capacity-allocation { display:grid; grid-template-columns:50fr 28fr 22fr; block-size:.65rem; gap:.2rem; margin-block:.4rem .65rem; }
.dcl-meter-gauge-stacked-capacity-allocation span { border:2px solid; border-radius:.2rem; } .dcl-meter-gauge-stacked-capacity-allocation span:first-child { background-color:currentColor; } .dcl-meter-gauge-stacked-capacity-allocation span:nth-child(2) { border-style:dashed; }
.dcl-meter-gauge-stacked-capacity-grid { grid-template-columns:repeat(3,minmax(0,1fr)); }
.dcl-meter-gauge-stacked-capacity[data-dcl-scheme="light"] { color: #11292f; background-color: #ffffff; border-color: #697f84; color-scheme: light; }
.dcl-meter-gauge-stacked-capacity[data-dcl-scheme="light"] .dcl-meter-gauge-stacked-capacity-muted, .dcl-meter-gauge-stacked-capacity[data-dcl-scheme="light"] .dcl-meter-gauge-stacked-capacity-eyebrow { color: #405a60; }
.dcl-meter-gauge-stacked-capacity[data-dcl-scheme="light"] .dcl-meter-gauge-stacked-capacity-well, .dcl-meter-gauge-stacked-capacity[data-dcl-scheme="light"] button, .dcl-meter-gauge-stacked-capacity[data-dcl-scheme="light"] kbd { color: #11292f; background-color: #e4edef; border-color: #697f84; }
.dcl-meter-gauge-stacked-capacity[data-dcl-scheme="light"] .dcl-meter-gauge-stacked-capacity-accent, .dcl-meter-gauge-stacked-capacity[data-dcl-scheme="light"] button:hover { color: #ffffff; background-color: #00535a; border-color: #00535a; }
.dcl-meter-gauge-stacked-capacity[data-dcl-scheme="light"] :focus-visible { outline: 3px solid #005c62; outline-offset: 2px; }
.dcl-meter-gauge-stacked-capacity[data-dcl-scheme="light"] meter, .dcl-meter-gauge-stacked-capacity[data-dcl-scheme="light"] progress, .dcl-meter-gauge-stacked-capacity[data-dcl-scheme="light"] input { accent-color: #00535a; }

.dcl-meter-gauge-stacked-capacity[data-dcl-scheme="dark"] { color: #eff8f9; background-color: #142f36; border-color: #839fa5; color-scheme: dark; }
.dcl-meter-gauge-stacked-capacity[data-dcl-scheme="dark"] .dcl-meter-gauge-stacked-capacity-muted, .dcl-meter-gauge-stacked-capacity[data-dcl-scheme="dark"] .dcl-meter-gauge-stacked-capacity-eyebrow { color: #b0c9ce; }
.dcl-meter-gauge-stacked-capacity[data-dcl-scheme="dark"] .dcl-meter-gauge-stacked-capacity-well, .dcl-meter-gauge-stacked-capacity[data-dcl-scheme="dark"] button, .dcl-meter-gauge-stacked-capacity[data-dcl-scheme="dark"] kbd { color: #eff8f9; background-color: #1c3c44; border-color: #839fa5; }
.dcl-meter-gauge-stacked-capacity[data-dcl-scheme="dark"] .dcl-meter-gauge-stacked-capacity-accent, .dcl-meter-gauge-stacked-capacity[data-dcl-scheme="dark"] button:hover { color: #11292f; background-color: #8fe1da; border-color: #8fe1da; }
.dcl-meter-gauge-stacked-capacity[data-dcl-scheme="dark"] :focus-visible { outline: 3px solid #8fe1da; outline-offset: 2px; }
.dcl-meter-gauge-stacked-capacity[data-dcl-scheme="dark"] meter, .dcl-meter-gauge-stacked-capacity[data-dcl-scheme="dark"] progress, .dcl-meter-gauge-stacked-capacity[data-dcl-scheme="dark"] input { accent-color: #8fe1da; }
</style>

When to use

Use to explain which categories contribute to a single capacity. Keep the bar segments, native reading and breakdown consistent.

Avoid

Do not use a breakdown when its parts have different totals or units.

Accessibility

The decorative split bar is duplicated by a native meter and a text definition list. Main text contrast is 15.2:1 in light and 13.1:1 in dark.

Was this useful? Send feedback.