CSS Units — px, em, rem, vw, vh Explained
Absolute Units
Absolute units represent a fixed measurement. They do not scale naturally based on the screen or parent element, so they are best used when exact sizing is truly needed.
Relative Units
Relative units scale in relation to another value, such as the root font size, parent font size, viewport size, or container size. These units are much more useful for responsive design.
| Unit | Relative To | Common Use |
|---|---|---|
em | Current element font size | Component spacing tied to local text |
rem | Root font size | Consistent spacing and typography |
% | Parent size | Fluid widths and layout sizing |
vw | Viewport width | Full-width sections, fluid typography |
vh | Viewport height | Hero sections, full-screen panels |
ch | Width of the "0" character | Readable text line lengths |
Common Unit Patterns
html {
font-size: 16px;
}
body {
font-size: 1rem;
line-height: 1.6;
}
h1 {
font-size: 2.5rem;
}
.container {
width: 90%;
max-width: 72rem;
}
.hero {
min-height: 100vh;
}
.article {
max-width: 65ch;
}
Choosing the Right Unit
FAQ
Frequently Asked Questions
Key Takeaways
- CSS units can be absolute or relative depending on whether they scale with context.
- rem, %, vw, vh, and ch are especially useful for responsive design.
- rem is a strong default for typography and spacing in many projects.
- Use px when precision matters, but avoid forcing fixed sizes everywhere.
- Choosing the right unit makes layouts easier to maintain and more adaptive.
Level Up Your Css Skills
Master Css with these hand-picked resources
10,000+ learners
Free forever
Updated 2026
Related CSS Topics