CSS units become a responsive design tool when you treat them as a decision about what each value should track: the viewport, the root font size, the parent element's size, or nothing at all. The core method is to pick a unit whose reference matches the thing that should change—use viewport units for full-bleed scale, rem for type and spacing that respect user font settings, percentages and fr for fluid containers, and container query units for component-level adaptation. clamp() turns any of these into bounded fluid values. You then check the result against zoom, long text, and narrow screens rather than trusting a single browser preview.
The unit choice rarely matters in isolation; the design intent does. A hero headline that should shrink on phones and stay readable on a 4K monitor needs a fluid-but-capped value, while a button's padding should probably scale with text size, not the viewport. Getting this mapping right is most of the work. The rest is testing, and knowing where each unit breaks down.
Start by naming what each value should follow
Before touching code, list the elements on the page and ask what each dimension should respond to. This single habit prevents most responsive bugs, because a mismatched reference is the usual root cause.
Sort values into four reference categories:
User text settings: font sizes, line heights, spacing around text, and control sizes that should grow when someone increases their default font. Root-relative rem and em serve these. Viewport size: full-bleed sections, hero heights, and elements that should genuinely fill the screen. Viewport units (vw, vh, dvh) fit, with caveats covered later. Parent or component size: anything inside a card, sidebar, or grid cell that should adapt to its own box rather than the whole window. Percentages, fr, and container query units (cqi, cqw, cqh) do this. Fixed reality: hairlines, icon strokes, and values tied to physical or platform constants. Pixels and other absolute units still earn a place here.
A practical example: a pricing card's width should follow the grid (percentage or fr), its internal padding should follow text size (rem or em), its header text should be fluid but capped (clamp() with rem and vw), and its 1px border should stay a pixel. Four units, four different jobs, all in one component. That is normal and correct.
The failure mode is using one unit everywhere. A layout built entirely in px ignores user font settings; a layout built entirely in vw shrinks text to unreadable sizes on phones and inflates it absurdly on wide monitors. Mixed units are not a compromise—they are the design.
Use root-relative units for anything tied to reading
rem means "root em": it equals the font size of the element, which browsers default to 16px but which users can change. That user-changeability is the whole point. Sizing text and space in rem means a reader who sets their browser default to 20px gets a proportionally larger, still-coherent interface.
em, by contrast, is relative to the current element's font size (or the parent's, for font-size itself). That makes em useful for spacing that should scale with the local text:
Here the padding is 1.5 times whatever the card's font size resolves to. If someone boosts text size, the padding grows with it and the card stays comfortable.
Two watch-outs. First, em compounds: nested elements each multiply, so a deeply nested list styled in em can shrink or balloon unexpectedly. Second, rem does not compound—every rem value points to the same root—which is why it is the safer default for typography scales and global spacing tokens. A common pattern is a small set of rem-based tokens (--space-sm: 0.5rem, --space-md: 1rem, and so on) used throughout, with em reserved for genuinely local, text-relative tweaks.
A note on rem and media queries: browser zoom and default-font changes affect rem values, but media query breakpoints written in em also respond to user font size, whereas breakpoints in px do not. Writing @media (min-width: 48em) means the layout switches at 768px by default but adapts if the user enlarges text—a small accessibility win that costs nothing.
Handle viewport units knowing their mobile quirks
vw and vh are percentages of the viewport's width and height. They are ideal for values that should track the window: a full-width banner, a hero that fills the first screen, decorative offsets.
The classic trap is 100vh on mobile. Browser UI (address bars, toolbars) can expand and collapse, so vh historically referred to the largest possible viewport, causing a 100vh hero to overflow or hide content behind chrome. Modern CSS addresses this with new units: svh (small viewport height), lvh (large), and dvh (dynamic, updating as UI shows and hides). For a hero that should always fit the visible screen at load, min-height: 100svh is the conservative choice; 100dvh fits the current visible area and updates as chrome moves, which can cause layout shifts during scroll.
vw has its own hazard: on some platforms, 100vw includes the scrollbar width, producing horizontal overflow. A safer full-bleed pattern uses percentages of the body or a container, or accounts for the scrollbar explicitly. If you must use vw for full width, test with a visible scrollbar on desktop.
There is also a readability cliff. Text sized in vw with no bounds becomes tiny on narrow screens and enormous on ultrawide ones. Treat raw vw typography as a starting point for a bounded formula, not a finished decision.
Build fluid scale with clamp() instead of raw viewport text
clamp(min, preferred, max) returns the preferred value unless it falls below the minimum or above the maximum. This is the standard way to make text and space fluid without losing bounds:
The minimum is 2rem, the maximum 4rem, and in between the size grows with 3vw plus a 1.25rem offset. Doing the arithmetic makes the behavior predictable. Suppose the root is 16px: the minimum is 32px, the maximum is 64px. The preferred value equals the minimum when 1.25rem + 3vw = 2rem, that is 3vw = 0.75rem = 12px, so vw = 4px, meaning a 400px viewport. It equals the maximum when 3vw = 2.75rem = 44px, so vw ≈ 14.67px, a viewport of roughly 1467px. Between 400px and about 1467px, the headline scales smoothly; outside that, it is capped. Those numbers are illustrative for a 16px root and change if the user's default differs—which is exactly why the rem parts are there.
Use the same shape for spacing: padding: clamp(1rem, 3vw, 2.5rem) keeps sections comfortable on phones without huge gaps on desktops. Keep minimums in rem so they respect user settings, and avoid putting the entire type scale in one giant clamp()—a few fluid steps (headings, hero, major section spacing) plus fixed rem steps for body text is easier to reason about and less likely to produce jarring ratios.
Let containers, not the window, drive component sizes
A sidebar card and a full-width hero should not respond to the same reference. Percentage widths and the fr unit handle the coarse case: grid-template-columns: 1fr 2fr splits available space in a ratio, and percentage widths size children against their parent. These are the workhorses of fluid layout.
Container query units go further. When an element is declared a query container (container-type: inline-size), units like cqi (1% of the container's inline size) and cqw/cqh measure the container, not the viewport. That means the same card component can render large in a main column and compact in a sidebar without any viewport media queries:
This is the modern answer to "responsive to what?"—the component answers to its own allotted space. Browser support for container queries and their units is broad in current evergreen browsers as of 2026, but older environments may not honor them; a sensible fallback is percentage-based sizing plus viewport media queries, which degrade gracefully. Check your actual support target before relying on cqi for critical sizing.
Cap lines and images in the units that fit them
Line length is a readability constraint best expressed in ch, the width of the "0" glyph in the current font. Roughly 45–75 characters per line is comfortable for body text, so max-width: 65ch on article text is a robust, font-relative cap that keeps measure sane regardless of container width.
Images and media want intrinsic behavior first: max-width: 100%; height: auto; prevents overflow, and aspect-ratio reserves space before load to avoid layout shift. For art-directed crops that change with viewport, object-fit: cover combined with a height in svh or a clamp() value works well. Avoid setting images in pure vw widths inside padded containers—the padding plus 100vw can overflow; use width: 100% of the parent instead.
Keep absolute units for the few jobs they do best
Pixels are not obsolete. Use them for values where a physical or platform constant is the point: 1px borders and hairlines, focus outlines that must remain visible, icon stroke widths at small sizes, and box shadows where a fixed blur is intentional. The px unit in CSS is not a literal device pixel—it is an angular reference that browsers scale—but it behaves consistently enough for these fine details.
The mistake is using px for type and spacing, which locks the design to the developer's assumed font size and ignores the reader's settings. A useful test: set your browser's default font size to 24px and reload. Text and spacing in rem/em should scale coherently; a layout dominated by px will look cramped and unchanged.
Verify with a repeatable check, not a single preview
Responsive unit decisions fail in predictable ways, so test for those specifically:
1: Resize continuously, not just at breakpoints. Drag the window from narrow to wide and watch for jumps, overflow, and text that becomes tiny or huge. Fluid values should change smoothly between their caps. 2: Zoom to 200% and 400%. Check that content reflows, nothing overlaps, and no horizontal scrolling appears on text-heavy pages. This catches px-locked layouts and fixed widths. 3: Change the browser's default font size to something like 20px and 24px. rem-based designs should scale; px-based ones will reveal themselves. 4: Test on a real phone or device emulation with dynamic chrome. Confirm that 100svh/100dvh heroes fit and that scrollbars do not cause 100vw overflow on desktop. 5: Resize a single component's container (for example, drop the card into a narrow sidebar) to confirm container query behavior and that cqi values respond to the component, not the window. 6: Check long and translated text. German or expanded UI strings lengthen; em-based padding and ch-based measure should still hold.
If something breaks, work backward from the reference mismatch: text too small on mobile usually means raw vw without a clamp() minimum; overflow at full width usually means 100vw plus padding or a scrollbar; cramped layouts when the user enlarges text usually mean px where rem belonged. Each symptom maps to a specific unit correction, which is faster than guessing at breakpoints.
As a final gate, run an automated accessibility check on contrast and reflow, and confirm that font sizes have not dropped below a comfortable minimum—typically 16px for body text—at the narrowest supported width. Units are a means to that end, not the end itself.
Frequently asked questions
Should I use rem or em for media query breakpoints? em in media queries responds to the user's default font size, so layouts switch earlier for people who enlarge text. If you want breakpoints tied to content and accessibility rather than device pixels, em is often the better choice; px breakpoints ignore user font settings.
Is dvh safe to use for full-screen sections now? It is widely supported in current browsers and fits the visible viewport dynamically, but it updates as mobile chrome hides and shows, which can cause content to shift during scroll. svh is the conservative option for content that must always be visible at load; dvh suits designs where slight movement is acceptable.
Why does my text get huge on a wide monitor? A raw vw font size has no upper bound, so it keeps growing with the window. Wrap it in clamp() with a maximum in rem, or switch to container query units so the text follows its component rather than the whole screen.
Do I still need pixels at all? Yes, for hairlines, borders, focus rings, and small fixed details where consistency matters more than scaling. The goal is not to eliminate px but to stop using it for type and spacing that should honor user settings.