Modern CSS has added functions and properties that replace whole categories of media-query and JavaScript hacks. The standouts:
clamp() — fluid, bounded values
h1 { font-size: clamp(1.5rem, , ); }
Modern CSS has added functions and properties that replace whole categories of media-query and JavaScript hacks. The standouts:
h1 { font-size: clamp(1.5rem, , ); }
clamp(min, preferred, max) gives fluid typography/spacing that scales smoothly with the viewport but stays within bounds — replacing several breakpoints' worth of font-size media queries with one line.
.video { aspect-ratio: 16 / 9; width: 100%; } /* height auto-computed to keep 16:9 */
.avatar { aspect-ratio: 1; } /* perfect square at any width */
Before this, keeping a responsive 16:9 box required the infamous padding-bottom: 56.25% hack. Now it's one declaration — and it reserves space (good for CLS) before images load.
.container { width: min(90%, 1200px); } /* whichever is SMALLER → fluid but capped */
.box { padding: max(1rem, 3vw); } /* whichever is LARGER → a minimum floor */
min()/max() pick the smaller/larger of values, letting one property be responsive without a media query (e.g. "90% wide, but never more than 1200px").
.card { display: grid; grid-template-rows: subgrid; grid-row: span 3; }
subgrid lets a nested grid inherit its parent's track lines, so items across separate cards (titles, bodies, buttons) align perfectly on shared rows — previously impossible without fixed heights.
.flex { display: flex; gap: 1rem; } /* gap now works in flexbox, not just grid */
These features eliminate long-standing hacks: clamp()/min()/max() replace stacks of media queries for fluid sizing, aspect-ratio replaces the padding hack and protects layout shift, and subgrid solves cross-component alignment.
They make responsive, proportional layouts dramatically simpler and more robust — modern CSS does declaratively what used to need JS or fragile tricks.
A library of IT interview questions with detailed answers — from Junior to Senior.
Donate