Ready, runs in your browser
0 chars · 0 words
default root font size
16
bytes leaving your device
0
signup or run limit
None

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.

FAQ

Everything answered. PX to REM converter, frequently asked

How do I convert px to rem in CSS?

Divide each pixel value by the root font size. Paste the block here and every px value is converted in one pass.

What is 16px in rem?

1rem at the default base of 16. 24px is 1.5rem and 32px is 2rem.

Is the converter free?

Yes, with no signup, no length cap and no run limit.

Is my stylesheet uploaded?

No. The conversion runs on your own device, so a client file never leaves your machine.

Can I paste a whole stylesheet?

Yes. There is no length limit, because nothing is being sent anywhere.

Can I change the root font size?

Yes, it is the one setting on the page. Everything is divided by whatever you enter.

What if I enter an invalid root font size?

Zero and negative values are rejected with the message Enter a valid root font size, and your CSS is left unchanged.

Will it convert my 1px borders?

Yes, to 0.0625rem. There is no skip option, so restore hairline borders during the review.

Can it break image references?

Yes. A filename containing a px value inside url() gets rewritten, so search the output for url( afterwards.

Does it convert 0px?

Yes, to 0rem. It works, though plain 0 is tidier.

Why do some results have sixteen decimal places?

There is no rounding step. Bases that are not powers of two produce long exact values.

Can I control the number of decimal places?

No. There is no rounding setting, so trim long values by hand.

Does it handle negative and decimal values?

Yes. Both -8px and .5px are converted correctly.

Does it match uppercase PX?

Yes, and the output is written lowercase as rem regardless.

Why did 20 px stay as it was?

The number must be directly followed by the unit, with no space between them.

Can I mark a value to be left alone?

No. Every match is converted, which is why the review step exists.

Does it understand CSS syntax?

No. It is a text replacement, so it cannot tell a property value from a filename or a comment.

Can I upload or download a file?

No. Paste in, copy out.

What is the difference between rem and em?

Rem is relative to the root font size. Em is relative to the parent's font size, so nested elements compound.

Should I convert everything to rem?

No. Typography and spacing gain the most. Anything that must stay exactly one pixel should stay in px.

How do I convert back to px?

Use the rem to px converter, which multiplies by the root font size instead.