New CSS features can improve a component while older browsers still need a readable base style. A feature query with @supports lets the stylesheet apply an enhancement only when the browser understands the tested declaration.
The fallback-first pattern keeps the normal rule outside the feature query, then places the newer declaration in a later @supports block. That order matters because unsupported browsers ignore the whole block, while supported browsers read the later rule and let it override the fallback through normal source order.
Feature queries test syntax support, not every rendering bug or design requirement. The condition needs to match the exact property-value pair used by the enhancement. A fixed-height media block can remain rectangular as a fallback while browsers that support aspect-ratio display it as a square.
Steps to add CSS feature-query fallbacks:
- Create index.html in your text editor with the card markup.
- index.html
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS feature-query fallback</title> <link rel="stylesheet" href="styles.css"> </head> <body> <article class="feature-card"> <div class="feature-card__media" aria-hidden="true"></div> <h1>Layout fallback</h1> <p>The card stays readable with or without a square media block.</p> </article> </body> </html>
- Create styles.css in your text editor with the fallback styles.
- styles.css
body { margin: 24px; background: #f1f5f9; color: #1e293b; font: 18px/1.5 sans-serif; } .feature-card { max-width: 320px; padding: 24px; border: 1px solid #cbd5e1; border-radius: 16px; background: white; } .feature-card__media { width: 160px; height: 96px; border-radius: 12px; background: linear-gradient(135deg, #2563eb, #0f766e); }
The media block has a usable 160 × 96 px shape even when the browser ignores the feature query.
- Append the @supports enhancement to the end of styles.css.
- styles.css
@supports (aspect-ratio: 1 / 1) { .feature-card__media { height: auto; aspect-ratio: 1 / 1; } }
The later rule overrides the base height only when the browser accepts (aspect-ratio: 1 / 1). Setting height to auto lets the ratio determine the height from the 160 px width; keeping both fixed dimensions would prevent the ratio from changing the shape.
- Save index.html and styles.css in the same folder.
- Open the saved index.html file in a current browser.

- Confirm that the gradient block is square above the card text.
A browser that supports aspect-ratio shows a 160 × 160 px block. Without that support, the block keeps its 160 × 96 px fallback and the text remains visible below it.