PX to REM Converter · Tutorial
How to convert a stylesheet from px to rem
6 min readbeginnerUpdated
An accessibility review asked you to make text and spacing scale with the user’s font size. This tutorial converts an existing stylesheet from px to rem with the bulk converter, explains what stays in px and why, and checks the result.
What you need
- The PX to REM Converter
- Your CSS, or the sample stylesheet from the Try it button
Steps
Check the root font size
Look at your CSS for a font-size on
html. If there is none, the browser default is 16 px; keep Root font size at 16. If your project setshtml { font-size: 62.5%; }, enter 10.Paste the stylesheet
Paste the CSS into CSS with px. The converted version appears on the right, and the message says how many values changed. In the sample, padding, margins, radii, font sizes and line heights become rem.
padding: 24px 32px; → padding: 1.5rem 2rem; font-size: 15px; → font-size: 0.9375rem; border: 1px solid; → border: 1px solid;Keep hairlines in px
Keep values up to is set to 1 px, so the 1 px border stays as it is. Raise it to 2 if you also want 2 px borders and outlines to stay fixed.
Decide about media queries
By default,
@media (min-width: 768px)is left alone. Tick Also convert @media queries to get48rem, so the layout switches earlier when users enlarge text, which many accessibility guides recommend.Copy and test
Copy the result into your project. Then set your browser’s default font size to 20 or 24 in its settings and reload: text and spacing should grow together without overlapping.
Try it yourself
Opens the PX to REM Converter with this tutorial's sample loaded.
Common mistakes
- Converting with the wrong base
- If the root font size is 10 px but you convert at 16, everything shrinks. Check the html font-size first.
- Converting image and icon sizes blindly
- Fixed-size icons or images might look odd when they scale. Review width and height values after converting.
- Mixing rem and em by accident
- The bulk converter writes rem, which doesn’t compound. If you later switch some values to em, remember they multiply inside nested elements.
Next steps
Go back to the PX to REM Converter, or keep going with one of these:
FAQ
Does it change values inside comments or strings?
No. Comments, quoted strings and url() values are skipped, so file names and notes stay intact.
How precise are the rem values?
Up to four decimal places, such as 0.9375rem for 15 px, which is exact enough for any screen.