Note Mobile-first (min-width) is the recommended approach: start with small screens and add complexity at wider breakpoints. Common breakpoints: 640px (small), 768px (medium), 1024px (large), 1280px (extra large).
media queryresponsivebreakpointmobile firstscreen size
Note prefers-color-scheme detects dark/light mode system preference. prefers-reduced-motion is critical for accessibility. hover: hover avoids applying hover styles on touch devices where hover is awkward.
dark modereduced motionhover detectionuser preferencecolor schemeaccessibility media
Note Container queries respond to the size of a parent container rather than the viewport. This makes components truly self-contained. Set container-type on the parent to opt in. Use container-name when you need to target a specific ancestor.
Note clamp() eliminates the need for many media queries. It sets a preferred value that flexes between a minimum and maximum. The preferred value usually includes a viewport unit so it scales fluidly. Ideal for typography and spacing.
Note On mobile browsers, 100vh is taller than the visible area because it does not account for the URL bar. Use 100dvh (dynamic viewport height) which updates as the browser chrome appears and disappears. svh is the smallest possible viewport, lvh is the largest.
viewport heightvhvwdvhfull screenviewport units
Min & Max Functions
syntax
min(value1, value2, ...)
max(value1, value2, ...)
example
.container {
width: min(90%, 1200px);
/* same as: width: 90%; max-width: 1200px; */
}
.sidebar {
width: max(200px, 20%);
/* at least 200px, grows with container */
}
.padding-responsive {
padding: max(16px, 3vw);
}
Note min() picks the smallest value, acting like a max-width. max() picks the largest, acting like a min-width. You can mix units freely inside these functions. They often replace media queries for simple responsive adjustments.
min functionmax functionresponsive widthfluid layoutmin max css
Note Range syntax is more readable than the traditional min-width/max-width approach. It is supported in all modern browsers. You can use <, <=, >, and >= operators. This replaces awkward constructs like (max-width: 1023.98px).
media rangerange syntaxbetween breakpointsmodern media query
Note Container query units (cqi for inline, cqb for block) are relative to the container's dimensions, not the viewport. 1cqi equals 1% of the container's inline size. They allow truly component-relative sizing.