The job
What the px to rem converter does
You have a stylesheet written in pixels and a reason to move it to rem, usually an accessibility review. Paste the block, set the root font size, and every px value in it is divided by that number and rewritten as rem.
It all happens in the browser. No upload, which matters when the stylesheet is a client's, no signup, no length cap, and no limit on how many times you run it.
The workflow
How to convert px to rem in three steps
Three steps, and the third one is the difference between a converted stylesheet and a broken one.
- Step 1
- Set the root font size. Leave it at 16 unless your project sets html to something else.
- Step 2
- Paste the CSS block and press Convert. Every px value is rewritten at once.
- Step 3
- Work the review list below before pasting anything back into the codebase.
Before you paste it back
What to review in the converted CSS
The conversion is a text replacement with no knowledge of CSS, so it converts values it should have left alone. These are the four to check, and all four are quick.
- url() paths
- A file named icon20px.png becomes icon1.25rem.png and the image stops loading. Search the output for url( and fix any that changed.
- Hairline borders
- border: 1px becomes 0.0625rem. If it should stay one pixel, put it back.
- Zero values
- 0px becomes 0rem. Harmless, but plain 0 is cleaner.
- Long decimals
- Nothing rounds, so an awkward base can produce sixteen decimal places. Trim them if the file has to read well.
The one setting
Choosing the root font size
The Root font size field is the divisor. At the default of 16, which matches the browser default, 16px is 1rem, 24px is 1.5rem and 32px is 2rem. If your project declares a different value on html, put that number in instead and the whole conversion shifts with it.
Zero and negative numbers are rejected rather than producing nonsense: the tool returns Enter a valid root font size and leaves your CSS alone. A base of 10 is accepted if your project works that way, and turns 18px into 1.8rem.
Predicting the output
Which values the converter will and will not touch
Useful to know before you paste a large file, because it tells you where to look afterwards.
- Converted
- Any number directly followed by px, including negatives like -8px and decimals like .5px.
- Also converted
- Uppercase PX, since matching ignores case. The output is always lowercase rem.
- Left alone
- A space before the unit, so 20 px is untouched, and a unit with anything appended, so 20pxx is untouched.
- No exceptions
- There is no way to mark a value as do not convert. Everything matching the pattern is converted.
The reason
Why the conversion is worth doing
Pixels are absolute and rem units are relative, and only one of those respects a reader's own settings. Someone who has raised their browser default font size, often for low vision or for cognitive reasons, sees rem-based type and spacing scale with that choice, while pixel values simply ignore it. That is why rem sits behind accessibility guidance on text resizing and readability.
It is also why the review list matters. Typography and spacing are what you want scaling. A one pixel divider was never meant to scale, and converting it is a regression dressed up as a fix.
Where it runs
Converting a client stylesheet safely
Most px to rem converters are hosted. Pasting a client's production stylesheet into somebody else's web form is a decision worth making deliberately, and plenty of agency contracts have something to say about it.
This one is a local transformation. The JavaScript that does the conversion is downloaded with the page and runs on your machine, so nothing is transmitted during a run. Load the page, disconnect, and it still converts. That is also why there is no run limit here: limits exist to protect a server, and no server is involved.
Where it fits
Who reaches for a px to rem converter
Developers doing an accessibility pass on an older codebase, where the finding was that text does not resize and the remedy is a unit change across a stylesheet. This turns an afternoon of find-and-replace into a paste and a review.
Designers converting a pixel-based mockup into the units a design system actually uses, and anyone maintaining a component library who needs one file moved without disturbing the rest. In every case the value is the same: the arithmetic is trivial, doing it a hundred times by hand is where the mistakes come from.