Progressive Enhancement in CSS
Building on broadly supported CSS first, with readable fallbacks and @supports guards, then layering on newer features for browsers that support them.
Content tagged progressive-enhancement
Snippet:
:playingand:paused: Style Media by Playback StateStyle audio and video players from their playback state.Style audio and video by playback state with CSS :playing, :paused, :buffering and :muted, plus :has() patterns and a JavaScript fallback.Tutorial:
contrast-color(): Automatic Readable Text on Any BackgroundLet CSS choose readable white or black text automatically.Use CSS contrast-color() to pick white or black text for any background colour: how the spec defines it, custom properties and brand colours, buttons and tags, pairing with light-dark(), mid-tone limits, and an @supports fallback.Tutorial:Animate and Type-Check CSS Variables with
@propertyGive CSS custom properties real types so they animate.Register CSS custom properties (CSS variables) with @property — a syntax, an inherits rule and an initial value — so they animate in transitions and keyframes, fall back safely on invalid values and always have a default. Covers rotating gradients, counting numbers and per-axis motion, CSS.registerProperty(), performance, browser fallbacks and common pitfalls.Tutorial:Animating
height: autoin CSS withinterpolate-sizeAnimate height to auto in pure CSS, no JavaScript.Animate height: auto in CSS with interpolate-size and calc-size(): smooth accordions and details panels without JavaScript, plus fallbacks and reduced motion.Tutorial:Auto-Growing Textareas with CSS
field-sizing: contentAuto-grow textareas with one line of CSS, no JavaScript.Make a textarea grow and shrink with its text using CSS field-sizing: content: no scrollHeight JavaScript, plus size limits, fallbacks and browser support.