Area charts — line charts with the region beneath the line filled in — are rare in pure HTML and CSS examples, unlike bar and line charts. The technique below builds one from a semantic, accessible markup base, using clip-path to carve each column into the shape the chart needs.

Markup and data passing

A simple chart can be an <ul> as the wrapper, with one <li> per data item. Any other elements work just as well, depending on the project.

<ul class="area-chart">
  <li> 40% </li>
  <li> 80% </li>
  <li> 60% </li>
  <li> 100% </li>
  <li> 30% </li>
</ul>

Because CSS cannot read the text inside an element, the data reaches the stylesheet through custom properties. Every item carries a --start and an --end:

<ul class="area-chart">
  <li style="--start: 0.1; --end: 0.4;"> 40% </li>
  <li style="--start: 0.4; --end: 0.8;"> 80% </li>
  <li style="--start: 0.8; --end: 0.6;"> 60% </li>
  <li style="--start: 0.6; --end: 1.0;"> 100% </li>
  <li style="--start: 1.0; --end: 0.3;"> 30% </li>
</ul>

Design constraints

Three principles shape the styling that follows:

  • Unitless values: the markup holds bare numbers, with no px, em, rem or %. Both --start and --end are numbers between 0 and 1.
  • Fluid column width: no fixed width is set on the <li> elements, and percentages are avoided because the item count is unknown. Each column instead takes the wrapper's width divided by the number of data items — here, the <ul> width divided by the number of <li> elements.
  • Accessibility: only the two custom properties are strictly required, but the text inside each <li> is optional and worth keeping so screen readers and other assistive technologies have something to announce.

Laying out a single series

The wrapper is a flex container: items sit in a row and stretch to fill the whole area.

.area-chart {
  /* Reset */
  margin: 0;
  padding: 0;
  border: 0;

  /* Dimensions */
  width: 100%;
  max-width: var(--chart-width, 100%);
  height: var(--chart-height, 300px);

  /* Layout */
  display: flex;
  justify-content: stretch;
  align-items: stretch;
  flex-direction: row;
}

If the wrapper is a list, its list styling should be removed to free up the layout.

ul.area-chart,
ol.area-chart {
  list-style: none;
}

Bar charts are straightforward — each column takes a background-color and a height. An area chart instead uses clip-path to define which region of a column is visible. First, the per-column setup:

.area-chart > * {
  /* Even size items */
  flex-grow: 1;
  flex-shrink: 1;
  flex-basis: 0;

  /* Color */
  background: var(--color, rgba(240, 50, 50, .75));
}

A polygon() that covers the entire area establishes the full rectangle. At this stage it has no visible effect, since the polygon encloses everything:

.area-chart > * {
  clip-path: polygon(
    0% 0%,     /* top left */
    100% 0%,   /* top right */
    100% 100%, /* bottom right */
    0% 100%    /* bottom left */
  );
}

The actual shape comes from feeding --start and --end into that polygon, so only the band between them is drawn:

.area-chart > * {
  clip-path: polygon(
    0% calc(100% * (1 - var(--start))),
    100% calc(100% * (1 - var(--end))),
    100% 100%,
    0% 100%
  );
}

That single rule does all of the work.

Multiple datasets with a table

Real area charts often plot several series at once, layered for comparison. That requires more child elements than a list offers, so the <ul> gives way to a <table> — accessible, search-engine friendly, and readable as raw markup when the stylesheet fails to load.

<table class="area-chart">
  <tbody>
    <tr>
      <td> 40% </td>
      <td> 80% </td>
    </tr>
    <tr>
      <td> 60% </td>
      <td> 100% </td>
    </tr>
  </tbody>
</table>

The same --start and --end properties apply, again as numbers between 0 and 1.

<table class="area-chart">
  <tbody>
    <tr>
      <td style="--start: 0; --end: 0.4;"> 40% </td>
      <td style="--start: 0; --end: 0.8;"> 80% </td>
    </tr>
    <tr>
      <td style="--start: 0.4; --end: 0.6;"> 60% </td>
      <td style="--start: 0.8; --end: 1.0;"> 100% </td>
    </tr>
  </tbody>
</table>

The wrapper carries an .area-chart class and gets the general layout styling first:

.area-chart {
  /* Reset */
  margin: 0;
  padding: 0;
  border: 0;

  /* Dimensions */
  width: 100%;
  max-width: var(--chart-width, 600px);
  height: var(--chart-height, 300px);
}

The <tbody> then becomes a flex container, laying the <tr> elements out in a row at equal sizes:

.area-chart tbody {
  width: 100%;
  height: var(--chart-height, 300px);

  /* Layout */
  display: flex;
  justify-content: stretch;
  align-items: stretch;
  flex-direction: row;
}
.area-chart tr {
  /* Even size items */
  flex-grow: 1;
  flex-shrink: 1;
  flex-basis: 0;
}

For the layered look, the <td> elements have to overlap. Each one covers the full area of the <tr> that contains it:

.area-chart tr {
  position: relative;
}
.area-chart td {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

Now the polygon clipping is applied to each cell, exposing only the band between the two custom properties:

.area-chart td {
  clip-path: polygon(
    0% calc(100% * (1 - var(--start))),
    100% calc(100% * (1 - var(--end))),
    100% 100%,
    0% 100%
  );
}

Colors go on last. Semi-transparent values are important here — rgba(), or hsla() if preferred — so the layers blend rather than block one another:

.area-chart td {
  background: var(--color);
}
.area-chart td:nth-of-type(1) {
  --color: rgba(240, 50, 50, 0.75);
}
.area-chart td:nth-of-type(2) {
  --color: rgba(255, 180, 50, 0.75);
}
.area-chart td:nth-of-type(3) {
  --color: rgba(255, 220, 90, 0.75);
}

Why the approach holds up

Because the layout is flex-based, the number of HTML elements has no bearing on sizing: every item is equal. Only the wrapper's width needs to be set, and the items adjust from there, which keeps the chart responsive.

This covers one pure-CSS route to area charts. For advanced cases, the author's open source framework at ChartsCSS.org documents customization such as alternate orientations, axes, and reversed ordering without markup changes.