foundation
Units (px, em, rem, vw, vh, fr, %)
Choose the right units for sizing, spacing, and layout grids.
Learning checklist
- Root-based scaling
- Viewport + container units
- fr tracks in grid
Definition
Choose the right units for sizing, spacing, and layout grids.
Syntax
Example
Deep dive
Why this matters
Principles, mental models, and debugging clues tailored to the topic.
Visual intuition
Each property is paired with motion or color feedback so you build muscle memory, not just recall syntax.
Copy-ready CSS
Controls emit exact CSS you can copy. Use it as a starter token or paste into DevTools for instant validation.
Performance notes
Learn where reflow, repaint, or compositing occurs so you avoid jank and choose GPU-friendly paths.
Accessibility first
Focus-visible, reduced-motion, and contrast tips are woven into every lab to keep experiences inclusive.
Practice
Try recreating a UI card using this topic. Toggle between dark and light modes to validate token contrast and responsiveness.
Tip: use DevTools overlays (grid/flex) plus the copy CSS button.
Units & Functions
Play with clamp(), min(), and viewport units to build constraint-based sizing.
Try these
- Increase max to see upper bound loosen.
- Drop min to watch minimum size shrink on narrow viewports.
- Notice width uses min() to cap container across breakpoints.
Adjust min/max to see the clamped range. Width uses min() to cap the container across breakpoints.
.utility {
font-size: clamp(14px, 1vw + 1rem, 28px);
width: min(90vw, 640px);
}<div class="utility">Constraint-based sizing with clamp(), min(), and viewport units.</div>
Related topics
Keep exploring adjacent concepts.
foundation
Responsive Design
Fluid design systems built with constraints, clamps, and progressive enhancement.
View pagefoundation
Media Queries
Craft media queries for viewport, accessibility preferences, and device capabilities.
View pageintermediate
Container Queries
Component-driven responsiveness using container size instead of viewport.
View page