px, rem or em? Choosing CSS units for type and spacing
Reviewed 22 November 2026 · 6 min read · Written and maintained by Toolnexo
CSS gives you more than a dozen units for the same job, and the choice affects accessibility as much as appearance. Pixels are simple but ignore how people have set up their browsers. Relative units adapt, but em and rem behave differently in ways that surprise people the first time they nest elements. This guide explains what each unit is relative to, where each belongs, and how to convert between them. The conversions below come from the px to rem converter on this site, which runs in your browser.
What each unit is relative to
- px is a CSS pixel, a fixed reference length. On high-density screens one CSS pixel covers several device pixels.
- rem is the font size of the root (html) element. With the browser default of 16 px, 1rem is 16 px everywhere on the page.
- em is relative to the font size of the element it is used on or, for the font-size property itself, of its parent. It compounds when nested.
- % on font-size is a share of the parent's font size, so 150% behaves like 1.5em.
- vw and vh are 1% of the viewport width and height. They change when the window resizes.
- pt, pc, in, cm and mm are absolute units tied to the CSS reference of 96 pixels per inch. They matter mainly for print styles.
Why rem is the usual choice for type
Many people raise the default font size in their browser settings. Sizes written in rem follow that choice, so text and the layout built from it scale up. Sizes written in px do not, which can leave a reader with small type on a page that looked fine to the designer. Browser zoom works with both, but changing the default size is a separate setting that only relative units respect.
With a 16 px root, the common conversions are: 12 px is 0.75rem, 14 px is 0.875rem, 18 px is 1.125rem, 20 px is 1.25rem, 24 px is 1.5rem and 32 px is 2rem. The converter gives you any other value and lets you change the root size if your site uses something different.
How em compounds
Because em looks at the parent, nesting multiplies. If a list is set to 1.2em and each nested list inside it also uses 1.2em, the second level is 1.2 × 1.2 = 1.44 times the base size and the third level is about 1.73 times. That is sometimes what you want, for example a button whose padding grows with its own text size, and sometimes a bug.
A useful rule: use em for things that should scale with the element's own text, such as padding and margins on a button, and rem for global type sizes and layout spacing. Note that for properties other than font-size, em is based on the element's own font size, not the parent's.
The 62.5% root trick
Some teams set html { font-size: 62.5%; } so that 1rem equals 10 px on a default browser, which makes conversion easy: 16 px is 1.6rem and 24 px is 2.4rem. Because it is a percentage, it still scales with the user's setting. The catch is that everything inheriting from html is now small, so you must set body text back to something like 1.6rem.
It is a convenience, not a requirement. Many modern codebases keep the 16 px default and use a converter or a calc() helper instead. Enter 10 as the root size in the converter if you use the trick.
vw, vh and the mobile browser bars
Viewport units are handy for full-screen sections and fluid type, but 100vh on phones can be taller than the visible area because the address bar slides away. Newer units such as dvh, svh and lvh handle this by giving the dynamic, smallest and largest viewport heights. For fluid text, clamp() with a rem minimum and maximum keeps vw-based sizes from becoming unreadably small or huge.
A quick decision list
- Font sizes and most spacing: rem.
- Padding that should follow an element's own text: em.
- Borders, hairlines and shadows: px.
- Full-height or fluid sections: vw, vh or the newer dvh and svh units, with clamp() for limits.
- Print stylesheets: pt, cm or mm.
- Never rely on a media query alone for accessibility: test with a larger default font size in your browser.
Put it into practice
PX to REM Converter
Convert pixels to rem and back, plus em, pt, pc, inches, cm, mm, percent, vw and vh, using your own root font size, parent size and viewp…
Runs in your browserCSS Box Shadow Generator
Design layered CSS box shadows with sliders, 8 ready-made presets and a live card, button or circle preview, then copy the CSS or a Tailw…
Runs in your browserCSS Border Radius Generator
Round each corner with sliders or shape an organic blob, start from 11 presets like pill, leaf and egg, then copy the CSS or a Tailwind c…
Runs in your browserColor Contrast Checker
Check any foreground and background colour pair for accessibility: the WCAG contrast ratio, AA and AAA pass/fail for normal and large tex…
Runs in your browserHow this guide is maintained
This page is reviewed when the related tools change. It describes what the published tools actually do: the tools run in your browser tab, so your files stay on your device. If you find something inaccurate, email [email protected] and it will be corrected.
Other guides
- How to merge PDFs without uploading them6 min · 17 November 2026
- OCR a scanned PDF: accuracy, limits and privacy7 min · 17 November 2026
- Compress a PDF without destroying readability6 min · 17 November 2026