CSS-Only Bar Chart

This chart is rendered entirely with HTML and CSS. No JavaScript is required. The bars use width: calc(var(--value) * 1%) to size themselves proportionally. This means the chart works in contexts where JavaScript is unavailable: email clients, RSS readers, print stylesheets, and progressive enhancement scenarios.

Step 1: Pure CSS (No JavaScript)

This chart renders even with JavaScript completely disabled. Try it: open DevTools, disable JS, and reload.

Pageviews by Page

/home
1,250
/products
890
/blog
675
/about
430
/contact
320
Accessibility: Each bar has an aria-label attribute with the exact value, making the chart navigable by screen readers. The HTML structure itself is semantic — a screen reader can announce "1,250 pageviews for /home" without any JavaScript intervention. This is a significant advantage over Canvas-based charts, which are opaque bitmaps.

Step 2: Progressively Enhanced (JavaScript Adds Tooltips)

With JavaScript enabled, hovering over a bar shows a tooltip with details. The chart still works without JS — the tooltips are purely additive.

Pageviews by Page (Enhanced)

/home
1,250
/products
890
/blog
675
/about
430
/contact
320

The HTML

<div class="chart-bar">
  <span class="bar-label">/home</span>
  <div class="bar-track">
    <div class="bar-fill" style="--value: 100"
         aria-label="1,250 pageviews">
      <span class="bar-value">1,250</span>
    </div>
  </div>
</div>

The CSS

.bar-fill {
  height: 100%;
  width: calc(var(--value) * 1%);  /* 0-100 maps to 0%-100% */
  background: #16a085;
  border-radius: 4px;
  transition: width 0.6s ease;     /* Animate if value changes */
}

.bar-fill:hover {
  background: #0e7c6b;            /* Darken on hover — CSS only */
}

The Enhancement (JavaScript)

// Populate tooltip content from data attributes
document.querySelectorAll('.js-enhanced .chart-bar').forEach(bar => {
  const tooltip = bar.querySelector('.bar-tooltip');
  const page = bar.dataset.page;
  const views = parseInt(bar.dataset.views).toLocaleString();
  const bounce = bar.dataset.bounce;

  tooltip.innerHTML = `<strong>${page}</strong><br>`
    + `Views: ${views}<br>`
    + `Bounce: ${bounce}`;
});
When to use CSS charts: CSS charts are ideal when you need a simple bar or progress indicator that must work everywhere — email newsletters, no-JS environments, print stylesheets. They are fully accessible by default, require zero dependencies, and can be progressively enhanced with JavaScript for richer interaction. The trade-off: they are limited to simple horizontal or vertical bars. Anything requiring axes, gridlines, or non-rectangular shapes needs Canvas or SVG.