Skip to content

Stacked Bars

A copy-paste charts component in pure HTML & CSS. Zero dependencies, framework-agnostic, MIT-licensed.

ChartsHTMLCSSany framework

Copy into your project

HTML
<!-- Stacked Bars -->
<div class="nuda-stacked" role="img" aria-label="Stacked horizontal bars">
  <div class="nuda-stacked__row">
    <span class="nuda-stacked__label">A</span>
    <div class="nuda-stacked__track">
      <span class="nuda-stacked__seg nuda-stacked__seg--1" style="--w: 55%"></span>
      <span class="nuda-stacked__seg nuda-stacked__seg--2" style="--w: 25%"></span>
      <span class="nuda-stacked__seg nuda-stacked__seg--3" style="--w: 20%"></span>
    </div>
  </div>
  <!-- ...more rows -->
</div>
CSS
/* Stacked Bars
   Horizontal bars with three segments growing left-to-right.
   Customize: --sb-c1, --sb-c2, --sb-c3, --sb-track, --sb-height */

.nuda-stacked {
  --sb-c1: #e4ff54;
  --sb-c2: rgba(228, 255, 84, 0.55);
  --sb-c3: rgba(228, 255, 84, 0.25);
  --sb-track: rgba(255, 255, 255, 0.04);
  --sb-height: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-width: 240px;
  padding: 4px;
}

.nuda-stacked__row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nuda-stacked__label {
  font: 700 0.625rem ui-sans-serif, system-ui, sans-serif;
  color: #a1a1aa;
  width: 14px;
}

.nuda-stacked__track {
  flex: 1;
  display: flex;
  height: var(--sb-height);
  background: var(--sb-track);
  border-radius: 4px;
  overflow: hidden;
}

.nuda-stacked__seg {
  height: 100%;
  width: var(--w, 0%);
  transform: scaleX(0);
  transform-origin: left;
  animation: nuda-stacked-grow 1.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.nuda-stacked__seg--1 { background: var(--sb-c1); animation-delay: 0.05s; }
.nuda-stacked__seg--2 { background: var(--sb-c2); animation-delay: 0.2s; }
.nuda-stacked__seg--3 { background: var(--sb-c3); animation-delay: 0.35s; }

@keyframes nuda-stacked-grow {
  to { transform: scaleX(1); }
}

@media (prefers-reduced-motion: reduce) {
  .nuda-stacked__seg { transform: scaleX(1); animation: none; }
}

How to use Stacked Bars

Paste the HTML where you need it and the CSS into a global stylesheet (or a <style> tag). Every class is prefixed nuda- so it never collides with Tailwind or your own styles. Tweak the CSS custom properties to match your design system.

Works in React, Vue, Svelte, Astro, Next.js, Nuxt, Laravel Blade, Django, Rails — or a single .html file. No npm install, no build step.

More charts components

← Browse all NudaUI components