Skip to content

Lesson 46 of 52Performance and tooling

Cross-Browser CSS and Progressive Enhancement

Decide which CSS you can ship with Baseline, write fallbacks that really work, fix the classic Safari and iOS bugs, and support forced colours.

18 min read0/4 questions

The design review went well and the new pricing page looks great in Chrome on your laptop. Then the bug reports arrive. On iPhones the sticky "Choose plan" bar is hidden behind the browser toolbar, the email field zooms the whole page when tapped, and a customer on Windows with High Contrast turned on says the plan cards have no borders and the focused button is invisible. Nothing is broken in Chrome, which is exactly the problem. This lesson is about shipping CSS for every browser your users actually run: deciding what is safe to use, writing fallbacks that genuinely fall back, fixing the bugs that keep coming back on Safari, and testing in all three engines.

Three engines, not five browsers

There are dozens of browser brands but only three rendering engines that matter: Blink (Chrome, Edge, Opera, Samsung Internet, most Android browsers), Gecko (Firefox) and WebKit (Safari on macOS, and historically every browser on iOS). Testing "Chrome and Edge" tests one engine twice. Testing Chrome, Firefox and Safari covers almost everyone.

iOS is the special case. For years Apple required every iOS browser to use WebKit, so "Chrome on iPhone" was Safari's engine with Chrome's interface. Apple now allows other engines in some regions, but almost all iPhone users still run WebKit. For practical purposes, a bug in Safari is a bug on iPhones.

The good news is that engines disagree far less than they did. Since 2021 (it began as Compat 2021) the browser vendors have run a yearly Interop project: they agree on a list of focus areas (things like :has(), container queries, nesting, @scope, anchor positioning, view transitions), write shared tests in the web-platform-tests suite, and publish a dashboard of pass rates. Scores in the focus areas usually climb from patchy to well above 90% across all engines within the year. That is why so much new CSS now ships everywhere in months instead of years.

Baseline: a shared answer to "can I use this?"

"Can I use it?" used to mean reading a compatibility table and arguing about which versions mattered. Baseline turns that into a label, maintained by the W3C WebDX group and shown on MDN, caniuse and webstatus.dev.

  • Baseline Newly available: the feature works in the current stable versions of Chrome, Edge, Firefox and Safari, on desktop and mobile.
  • Baseline Widely available: it has been Newly available for 30 months, so the older browsers still in use support it too.
  • Limited availability: at least one core browser does not support it yet.
The life of :has() as a Baseline feature
  1. March 2022

    Safari 15.4 ships it first

    Limited availability. One engine supports it, so you can only use it as an enhancement.

  2. August 2022

    Chrome 105 and Edge follow

    Still limited. Firefox users get nothing, and the selector list containing `:has()` is ignored there.

  3. December 2023

    Firefox 121: Baseline Newly available

    Every core browser's current version supports it. Users on older versions do not.

  4. June 2026

    Baseline Widely available

    30 months later. Old phones and slow-updating machines have caught up, so most teams treat it as safe without a fallback.

Where do you check? MDN shows a Baseline badge and a compatibility table at the bottom of every property page. caniuse.com adds global usage percentages and known bugs in its notes, which is where you find "supported, but broken in Safari 16 when used inside a shadow root". webstatus.dev tracks every feature's Baseline status and the dates it changed. All three read from the same open data sets (browser-compat-data and web-features), and those are corrected over time, so a feature's status can occasionally move. Check before you rely on a date you remember.

A team policy beats case-by-case arguments

Senior engineers write the rule down once. A common one is:

Use Widely available features freely. Use Newly available features only with a fallback or as an enhancement. Use Limited availability features only as an enhancement that the page does not need.

Then check the policy against your analytics. A government service or a bank may still need older iOS versions; an internal tool used on managed laptops can be more aggressive. The policy also tells reviewers what to ask in a pull request: "This uses a Newly available feature; where is the fallback?"

Quick check
A property became Baseline Newly available in March 2026. What does that tell you in October 2026?
Need a nudge? A hint rules out a wrong answer.

Fallbacks that actually fall back

CSS has a built-in fallback mechanism: when a browser cannot parse a declaration, it drops it and the previous declaration for the same property still applies. So you write the old value first and the new one second.

.hero {
  height: 100vh;   /* every browser */
  height: 100dvh;  /* browsers that understand dvh replace the line above */
}
 
.button {
  background: #2563eb;                  /* fallback */
  background: oklch(0.55 0.2 260);      /* wider gamut where supported */
}

This works because the browser rejects the unknown value while parsing. Custom properties break that rule, and this catches out experienced developers. The browser cannot know what var(--x) will hold until it computes styles, so any declaration with var() is accepted at parse time. If the variable turns out to hold something invalid, the declaration becomes invalid at computed-value time, and the property falls back to its inherited or initial value, not to the declaration above it.

HTML & CSS
<style> .box { padding: 12px; margin: 8px 0; color: #111; border: 2px solid #111; } /* wobble() is not a real CSS function, so it stands in for any new value an old browser does not understand. */ .direct { background: #fde68a; background: wobble(1); } .via-var { --bg: wobble(1); background: #fde68a; background: var(--bg); } .guarded { background: #fde68a; } @supports (background: wobble(1)) { .guarded { --bg: wobble(1); background: var(--bg); } }</style><div class="box direct">Direct value: yellow, because wobble() was dropped at parse time</div><div class="box via-var">Through var(): transparent, the yellow line is lost</div><div class="box guarded">Guarded with @supports: yellow again</div>

Preview

The second box shows the trap. In a real codebase, --bg holds an oklch() or color-mix() value from your design tokens, and on a browser that does not understand it, every component using the token loses its colour completely. When the token itself uses new syntax, guard it with @supports, or have your build tool emit a plain fallback value.

Predict the outputHTML & CSS

A browser does not support the hypothetical glow() function. The paragraph sits inside a body with color: black. What colour is the paragraph text? Type the colour name.

:root { --accent: glow(red); }

p {
color: green;
color: var(--accent);
}
Need a nudge? Hints walk you through it.

@supports, including selectors

@supports tests whether the browser can parse a declaration, and selector() tests a selector. Use them to wrap whole blocks of enhancement, or with not to write a fallback that only old browsers see.

/* Enhancement: only browsers with :has() dim the other cards */
@supports selector(:has(a)) {
  .plans:has(.plan:hover) .plan:not(:hover) { opacity: 0.6; }
}
 
/* Fallback: only browsers WITHOUT container queries get a media query */
@supports not (container-type: inline-size) {
  @media (min-width: 40rem) { .card { display: flex; } }
}

Two limits. @supports checks parsing, not correctness, so a browser with a buggy implementation still passes. And a selector list with one unknown selector invalidates the whole rule, so never put a new pseudo-class in the same comma list as your fallback selectors.

Progressive enhancement versus graceful degradation

Both aim for a page that works everywhere. They start from opposite ends.

Progressive enhancement starts with HTML and CSS that work in every browser in your policy, then adds layers for browsers that can do more. A grid of cards uses display: grid for everyone, then @container rules make each card rearrange itself when there is room. A browser without container queries still gets a tidy grid.

Graceful degradation starts with the full modern design, then patches older browsers so they do not break. It is fine for small gaps, but it tends to leave the old path untested, because nobody looks at it.

Prefer enhancement for anything a user needs to complete a task, and accept a plainer look in old browsers. A checkout that renders with less polish is fine. A checkout whose Pay button is hidden because a positioning feature is missing is not. Anchor positioning is a good example: if a tooltip positioned with position-anchor has no fallback, wrap it in @supports (anchor-name: --a) and give other browsers a simple position: absolute placement first.

Tooling: let the build handle prefixes and syntax

You should not write vendor prefixes by hand. Tell your tools which browsers you support with a Browserslist query, in package.json or a .browserslistrc file, and they work out what to add.

package.json
{
  "browserslist": ["baseline widely available"]
}

Browserslist understands Baseline queries such as baseline widely available and baseline 2024, plus the older style like defaults or > 0.5%, last 2 versions, not dead. Two tools read it:

  • Autoprefixer (a PostCSS plugin) adds -webkit- and other prefixes your targets need, and nothing else.
  • Lightning CSS does prefixes too, but it also lowers new syntax: it flattens native nesting for browsers that lack it and adds plain colour fallbacks before oklch() or color-mix() values. Tailwind v4 uses it internally, and Vite can be configured to use it.

Know your framework's floor as well. Tailwind CSS v4 is built on cascade layers, @property and color-mix(), and its docs list Chrome 111, Safari 16.4 and Firefox 128 as the minimum. Older browsers do not get a degraded Tailwind site; they get broken styles. If your analytics show real traffic below those versions, that decides between Tailwind v3 and v4 before any other argument.

The Safari and iOS bugs that keep coming back

Most cross-browser tickets in a real team are the same handful of iOS issues. Learn them once.

100vh is taller than the screen. On iOS, 100vh equals the large viewport, the height with the browser toolbars hidden. When the page first loads the toolbars are showing, so a 100vh hero pushes its bottom (often the main button) off screen. The viewport units fix it: svh is the small viewport (toolbars visible), lvh the large one, and dvh the dynamic one that changes as toolbars move. Use min-height: 100svh for heroes. Use dvh carefully, since resizing content while the user scrolls can feel jumpy.

Tapping an input zooms the page. iOS Safari zooms in when you focus a field whose font size is below 16px, and does not zoom back out. The fix is font-size: max(16px, 1rem) on inputs, selects and textareas. Do not "fix" it with maximum-scale=1 in the viewport meta tag, which blocks zoom for people who need it.

position: sticky silently stops working. A sticky element sticks within its nearest scrolling ancestor. If any ancestor between it and the page has overflow: hidden, auto or scroll, that ancestor becomes the scroll container, it never scrolls, and the element never sticks. This happens in every engine, but the usual culprit is an overflow-x: hidden added to stop horizontal scroll on mobile. Use overflow-x: clip instead: it clips without creating a scroll container. DevTools helps here: walk up the ancestors in the Elements panel looking for an overflow declaration.

Native controls look different. Date and time inputs, selects, and range sliders are drawn by each engine and the OS, so the Safari date picker will never look like Chrome's. Style the box (border, padding, font) and accept the native picker, or use a tested component library. Do not try to pixel-match.

Some properties still need a prefix. backdrop-filter only became unprefixed in Safari 18, so -webkit-backdrop-filter is still needed if you support Safari 17. -webkit-text-size-adjust: 100% stops iOS inflating text when a phone rotates to landscape. Set 100%, not none, which can break user text zoom. Your prefixer adds these if Browserslist targets those versions.

Notches and home bars. On phones with a notch or a home indicator, set viewport-fit=cover in the viewport meta tag so the page can draw edge to edge, then pad fixed bars with the safe area so nothing hides under the system UI:

.bottom-bar {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
Match the pairs0/5 matched

Match each iOS or Safari symptom to its fix.

Choose an item, then its match on the other side.

Forced colours and Windows High Contrast

Windows contrast themes (shown in CSS as forced colours mode) replace your colours with a small palette the user picked, often light text on black. Chromium browsers and Firefox on Windows support it, and some people with low vision or migraines depend on it. In this mode the browser:

  • replaces color, background-color, border-color, outline-color and SVG fill and stroke with the user's system colours,
  • forces box-shadow and text-shadow to none,
  • drops background-image unless it is a url() image, so gradient backgrounds vanish.

Three common bugs follow. A focus ring drawn with box-shadow disappears completely. A card separated from the page only by a background tint or a shadow loses its edge. An icon drawn as a CSS mask or gradient vanishes, and a url() icon painted in a fixed dark colour becomes invisible on a black background.

The fixes are usually small. Keep a transparent border or outline on anything that needs an edge, because the browser recolours it to a visible system colour. Draw icons as inline SVG with fill="currentColor", so they follow the text colour. And when you need a targeted fix, use the media query with system colour keywords:

HTML & CSS
<style> .card { padding: 12px; background: #f1f5f9; box-shadow: 0 1px 3px #0003; border: 1px solid transparent; } .btn { padding: 8px 14px; border: 0; background: #2563eb; color: white; } .btn:focus-visible { outline: 2px solid transparent; box-shadow: 0 0 0 3px #93c5fd; } @media (forced-colors: active) { .btn { border: 1px solid ButtonText; } .tag { forced-color-adjust: none; background: Highlight; color: HighlightText; } }</style><div class="card"> <p>Plan: Pro <span class="tag">Popular</span></p> <button class="btn">Choose plan</button></div>

Preview

In Chrome or Edge, open DevTools, then Rendering > Emulate CSS media feature forced-colors: active, and press Tab to focus the button. The shadow ring is gone, but the transparent outline is now a visible system colour, and the card keeps its edge from the transparent border. forced-color-adjust: none opts one element out so you can paint it with system colours yourself. Use it sparingly, since it overrides the user's choice.

Quick check
Your focus style is outline: none; box-shadow: 0 0 0 3px blue;. What does a keyboard user see in Windows forced colours mode?
Need a nudge? A hint rules out a wrong answer.

A testing matrix that fits in CI

You cannot test every browser on every pull request by hand, so automate the engines and spot-check the devices.

Playwright runs the same tests in Chromium, Firefox and WebKit. Its WebKit build is close to Safari's engine, though not identical to Safari on a real iPhone, and it catches most layout differences cheaply.

playwright.config.ts
import { defineConfig, devices } from "@playwright/test";
 
export default defineConfig({
  projects: [
    { name: "chromium", use: { ...devices["Desktop Chrome"] } },
    { name: "firefox", use: { ...devices["Desktop Firefox"] } },
    { name: "webkit", use: { ...devices["Desktop Safari"] } },
    { name: "mobile-safari", use: { ...devices["iPhone 15"] } },
  ],
});

Add visual regression for key pages: await expect(page).toHaveScreenshot() stores a baseline image per browser and fails when the rendering changes. Keep screenshots to a few stable pages, generate them in the same Docker image as CI (fonts and anti-aliasing differ between operating systems), and mask dynamic content such as dates. Playwright can also emulate media features with page.emulateMedia({ forcedColors: "active", reducedMotion: "reduce" }).

For the bugs automation misses (toolbars, keyboards, real touch), test on a real iPhone and a real Android phone before big releases, or use a cloud device service such as BrowserStack or LambdaTest. The Safari Web Inspector setup from Browser DevTools for HTML, CSS and Performance lets you debug the phone directly.

Key terms
Baseline
A label for web features: Newly available when all core browsers support them, Widely available 30 months later.
progressive enhancement
Building a base that works in every supported browser, then adding features where the browser can handle them.
@supports
A conditional rule that applies CSS only if the browser can parse a given declaration or selector.
invalid at computed-value time
What happens when a var() resolves to an invalid value: the property becomes unset instead of using an earlier declaration.
Browserslist
A shared config of target browsers that tools like Autoprefixer and Lightning CSS read to decide on prefixes and fallbacks.
dynamic viewport units
svh, lvh and dvh: viewport heights with mobile toolbars shown, hidden, or tracked as they move.
forced colours mode
An OS setting, such as Windows contrast themes, that replaces page colours with a user-chosen system palette.