Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

Progressive enhancement in CSS

Progressive enhancement starts with a usable baseline, then adds optional styles according to supported features. Missing enhancements should not prevent access to the content.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

/* Baseline styles first; enhancements are optional. */
@supports (property: value) {
  /* Rules that require this feature. */
}

Progressive enhancement (progressive enhancement) is a strategy, not a CSS keyword. Start with a logical document structure and usable baseline styles. Then add enhancements while keeping the content accessible without them. Unlike graceful degradation, the starting point is the baseline rather than the most elaborate version.

Browsers ignore unsupported properties and values. For a single declaration, an earlier fallback value may therefore suffice; when other cascade conditions are equal, the later valid declaration wins. When several rules depend on one feature, group them inside @supports (property: value). Keep baseline styles outside that block: a browser without @supports support skips the entire block.

In the example, .cards uses display: block by default, with max-inline-size: 26rem limiting its inline size. The list items “Getting started” and “Next steps” appear one below the other. The grid is enabled only if all three @supports tests pass: (display: grid) and (grid-template-columns: 1fr 1fr) and (gap: 8px). The items then occupy two columns with an 8px gap, with no guarantee of a fixed column width. If the block is not applied, the vertical layout remains, with the same content in the same order.

A feature query does not guarantee bug-free rendering or accessibility of the overall design. Test both the baseline and enhanced versions. Specification indexes alone do not establish browser compatibility. The structured CSSWG indexes were reconciled with a pinned version of MDN BCD, but that does not replace verification of each example.

Examples

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Progressive enhancement with CSS Grid</title>
  <style>
    .cards { display: block; max-inline-size: 26rem; }
    .cards > li { padding: 0.5rem; background: #eee; color: #111; }
  </style>
  <style id="enhancement">
    @supports (display: grid) and (grid-template-columns: 1fr 1fr) and (gap: 8px) {
      .cards {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
      }
    }
  </style>
</head>
<body>
  <h1>Progressive enhancement with CSS Grid</h1>
  <ul class="cards" aria-label="Topics">
    <li>Getting started</li>
    <li>Next steps</li>
  </ul>
  <script>
    const cards = document.querySelector('.cards');
    const enhancement = document.getElementById('enhancement').sheet;
    enhancement.disabled = true;
    console.log('Baseline display: ' + getComputedStyle(cards).display);
    enhancement.disabled = false;

    const style = getComputedStyle(cards);
    if (style.display === 'grid') {
      const columns = style.gridTemplateColumns.trim().split(/\s+/).length;
      console.log(`Enhancement: grid, ${columns} columns, ${style.columnGap} column gap`);
    } else {
      console.log('Enhancement not applied; display: ' + style.display);
    }
  </script>
</body>
</html>

Result

Baseline display: block
Enhancement: grid, 2 columns, 8px column gap

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources