Px ↔ Rem Converter
Convert px to rem and back at any root font size — one value or a whole CSS block at once. Only the source unit is rewritten, and a reference table covers common sizes.
About this tool
A rem is whatever the root font size says it is. On a fresh browser that is 16px, so 24px divides into 1.5rem — but plenty of projects set the root to 62.5% (10px) to make the mental math easier, and a few design systems run 15px or 18px. That is why the root size here is an input, not an assumption: 24px is 1.5rem at root 16, 2.4rem at root 10, and 1.333rem at root 18.
The rewrite is deliberately narrow: in px → rem mode only values written in px are touched. If the block you paste is half migrated — some declarations already in rem — the converter leaves those alone, so you can run the same block through repeatedly without double-converting anything. The count shown above the result tells you exactly how many values were rewritten, which is the quickest way to spot that the input was not what you thought it was.
Rounding is part of the job. A 14px font at root 16 is 0.875rem exactly, but 15px is 0.9375rem — four decimals that nobody wants to read in a stylesheet. Pick two or three decimals and the tool writes a value you can actually paste; the reference table below lists the sizes that come up most, so for those you never need to type anything at all.
Why a px to rem result can round the wrong way in JavaScript
Because decimals such as 0.285 are not exactly representable in binary, so multiplying and rounding can land one step low. The conversion adds Number.EPSILON before rounding, which corrects the direction without changing values that were already exact.
The classic case is 2.675 rounded to two decimals. Multiply it by 100 and the stored value is a hair below 267.5, so the usual rounding returns 267 — wrong in the last place, and wrong in a way that is very hard to notice inside a stylesheet. The same wobble affects px values divided by a root size that is not a power of two.
Adding the smallest representable number before the multiply nudges values sitting exactly on the boundary upward and leaves everything else alone. Because the epsilon is smaller than any difference the rounding cares about, it cannot pull a genuinely lower value up into the next step.
The literal is tidied as well. Trailing zeros are not written, so 1.50rem comes out as 1.5rem, and a value that would otherwise print in exponential notation is written out in full. The result is something you can paste into a stylesheet, not a number that merely happens to print correctly.
What the block rewrite counts as a value worth converting
A number immediately followed by px or rem, with an optional sign and an optional fractional part. The unit must touch the number, so 24 px is left alone, and every other character in the pasted text is copied through unchanged.
Working on the text rather than on parsed CSS is what makes this safe to point at a stylesheet, a block of SCSS, or a fragment of a template. It never needs to know what it is looking at: it finds the pattern, decides whether the unit is the source unit for the chosen direction, and leaves the remaining characters exactly where they were.
The adjacency rule is the one thing that stops a value being rewritten. Because the pattern requires the unit to follow the number with nothing in between, a value written with a gap is treated as ordinary text. That is a rare way to write CSS, and treating it as text is better than guessing at something that may be part of a sentence rather than a declaration.
Only one unit is ever the source. In px to rem mode the pattern still matches every rem value in the text and deliberately returns each one untouched, so the count of rewritten values counts px values only and the same block cannot be converted twice by running it again.
Why the px to rem table changes with your root font size
The table is computed from the root size you entered rather than stored. At root 16, 24px reads as 1.5rem; at root 10 the same row reads 2.4rem. The rows are recomputed, so the table always describes the conversion in front of you.
The rows themselves are a fixed list of the sizes that come up most: the common type sizes up to 32px, and the spacing steps that are multiples of four out to 128px. The list is fixed because it is meant to be scanned; the numbers in it are not, because every one of them depends on the root size.
The same table answers both directions, since one column is simply the other divided by the root. That is why it needs no direction switch: whether you are converting into rem or back out of it, the pair 24px and 1.5rem settles the question.
It is also where a wrong root size becomes visible. If the table says 16px is 1.6rem, the root in the box is 10, not 16 — the numbers on screen are the quickest way to catch that the setting does not match the site you are working on.
Why the output is rem and never em
An em is relative to the parent font size, so the same declaration means a different number of pixels at every level of nesting. A rem always resolves against the root.
Take a card with a heading set at 0.8em inside a wrapper also set at 0.8em, in a body at 0.8em, on a 16px root. The wrapper renders at 12.8px, the heading inside it at 10.24px, and one more level gives 8.19px. One value, three sizes, and none of them visible in the CSS.
Rewritten as rem the same three levels all read 0.8rem and all render at 12.8px, because rem skips the parent chain entirely. That is the whole reason this converter offers rem: the number you type is the number you get, wherever the rule lands.
The root size stays an explicit input rather than a hardcoded 16 for the same family of reasons. A 62.5 percent reset makes 1rem equal 10px, and a stylesheet written against that root would convert to numbers twice as large if the tool assumed 16. Guessing the root would produce plausible-looking rem values that are wrong by a factor of 1.6.
Frequently asked questions
What root font size should I use?
Whatever your stylesheet actually sets on html (or :root). Browsers default to 16px, and if your CSS never changes it, 16 is correct. If you use the 62.5% reset, enter 10. Using the wrong root is the single most common way these conversions come out silently wrong — every value shifts by the same ratio, so nothing looks obviously broken.
Why were some values in my block left unchanged?
Only the source unit is rewritten. In px → rem mode, values already written in rem pass through untouched — that is deliberate, so a partially migrated stylesheet can be converted in one pass without converting the same declarations twice. Switch the direction and run it again if you need the other unit.
Should I convert everything to rem?
Usually not. Rem is right for type, spacing and layout that should respect the user’s font-size preference. Borders of 1px, box shadows, and media query breakpoints are commonly kept in px on purpose. The tool rewrites what you select; it does not try to decide what belongs in which unit.
Does it handle CSS functions, variables or comments?
It rewrites every number-with-unit occurrence anywhere in the text, including numbers inside function calls such as calc, inside custom property values and inside comments. That is usually what you want — but check the count: if you only meant to convert declarations and the count is higher than expected, something in a comment matched too.
Does anything I paste get sent anywhere?
No. The conversion is plain string arithmetic in the page. There is no server, no request and no logging, and the tool keeps working with the network switched off.
Related tools
Build a linear, radial or conic gradient and see the colours in between — interpolated in sRGB, linear light or OKLab — then copy the CSS. Runs entirely in your browser.
Fit a clip into a target aspect ratio and see exactly what gets cropped or letterboxed — for both cover and contain — with the crop rectangle and the loss in pixels. Runs entirely in your browser.
Generate names, emails, usernames, UUIDs, IP and MAC addresses, Luhn-valid card numbers and more — seeded so the same seed always yields the same rows, entirely in your browser.