When you need this conversion
Design files hand you sizes in pixels: a 24 px heading, 14 px captions, 32 px spacing. Modern CSS writes them in rem so the whole interface scales with the reader’s font setting. Converting keeps your implementation pixel-accurate at the default size and accessible at every other size.
Choosing the root size
- 16 px is the default in Chrome, Safari, Firefox and Edge. If your CSS never sets a font size on
html, use this. - 10 px if you use the 62.5% trick. The math gets easy (divide by 10), but remember to set a readable body size, for example
body { font-size: 1.6rem }. - Your own base if you set
html { font-size: 18px }or similar. A fixed px value onhtmlstops user settings from applying, so prefer a percentage.
Useful values at a 16 px root
- 12 px = 0.75 rem, 14 px = 0.875 rem, 18 px = 1.125 rem
- 20 px = 1.25 rem, 24 px = 1.5 rem, 32 px = 2 rem, 48 px = 3 rem
Common mistakes
Setting a fixed px size on html. html { font-size: 16px } looks harmless but overrides the user’s browser preference. Use 100% (or leave it alone) instead.
Using rem for borders. A 1 px border becomes 0.0625 rem and can round to 0 or 2 device pixels at some zoom levels. Hairlines are one of the few places px is still the better choice.
Going the other way? Use the rem to pixels converter.