CSS length units
Pixels, percentages and relative font units respond differently to their context.
5 minutes. No sign-up needed.
What you'll learn4 ideas
- A length in px ignores the space and text around it, though page zoom still enlarges every CSS pixel.
- A percentage width takes a share of the parent's content area, the containing block, so it changes when that space changes.
- A length in rem multiplies the html element's font size, so spacing follows the page-wide setting.
- A padding in em multiplies the element's own font size, while a font-size in em uses the parent's font size.