What is a REM to PX converter?
rem is a CSS unit relative to the font size of the root element (html). In most browsers that size is 16 px, so 1rem equals 16 px, 1.5rem equals 24 px and 0.875rem equals 14 px. Designers hand over sizes in pixels and developers often want them in rem, so text and spacing grow when a visitor raises the default font size in the browser. This tool converts in both directions and handles the whole family of CSS lengths: px, rem, em, pt, pc, in, cm, mm and %.
It has two modes. "One value" converts a single number and shows it in every unit at once, with a quick table from 4 px to 96 px. "A whole CSS" takes a stylesheet and rewrites every px as rem (or the reverse) in one pass. You set the root font size yourself, because some projects use the 62.5% trick, which makes the root 10 px, and others use 18 px or 20 px.
The math is simple, but it is easy to get wrong at scale. Everything runs in your browser. The values and the CSS you paste are never sent anywhere.
How to convert between rem and px
- Choose the tab "One value" or "A whole CSS".
- Under "Font sizes used by rem and em", check "Root font size (1rem)". The default is 16 px. In the single value tab you can also set "Parent font size (1em and 100%)".
- In "One value", type the number in "Value" and pick the "Unit" it is in. A comma works as the decimal separator.
- Read "The same length in every unit". Each line has its own copy button, and the line of the unit you typed is highlighted.
- Use the "Quick table (px to rem and em)" when you need a common size without typing, such as 14 px or 40 px.
- In "A whole CSS", paste your code into "CSS to convert", choose "px to rem" or "rem to px", and read "Converted CSS". The line "values changed" tells you how many lengths were rewritten.
- In "px to rem", set "Keep px up to (hairlines and borders)". The default is 1, so a
1pxborder is not turned into a tiny fraction. Copy the result with "Copy CSS".
Examples
24 px in every unit
With a root and parent of 16 px, 24px shows as:
px 24px
rem 1.5rem
em 1.5em
pt 18pt
pc 1.5pc
in 0.25in
cm 0.635cm
mm 6.35mm
% 150%Points, picas, inches and centimeters follow the CSS reference pixel, where 1 inch is exactly 96 px.
A different root size
Set the root to 10 px (the 62.5% setup) and the unit to rem, then type 1.25. The result is 12.5px. In the quick table, 14 px becomes 1.4rem and 40 px becomes 4rem, so the math is easy to do in your head.
Em depends on the parent
Set the parent font size to 20 px, choose the unit em and type 1.5. The result is 30px. The same happens with 150%, because percentages in font sizes also refer to the parent. Rem would still use the root size, which is why mixing them surprises people.
A whole stylesheet
Convert this CSS with "px to rem", root 16 and "Keep px up to" at 1:
.card {
padding: 24px 16px;
border: 1px solid #ddd;
font-size: 18px;
margin-bottom: 0.5rem;
background: url("icon-24px.svg");
}
@media (min-width: 768px) {
.card { padding: 32px; }
}The result changes four values, and only those:
.card {
padding: 1.5rem 1rem;
border: 1px solid #ddd;
font-size: 1.125rem;
margin-bottom: 0.5rem;
background: url("icon-24px.svg");
}
@media (min-width: 768px) {
.card { padding: 2rem; }
}The 1px border stays, the url() is untouched, and the media query keeps 768px. In "rem to px" mode, 1.5rem becomes 24px.
Common mistakes
- Assuming 1rem is always 16 px. It is the root font size. If the project sets another one, or the user changed the browser default, the result differs. Set the real root size in the tool.
- Converting media queries.
remandeminside media queries follow the browser default, not yourhtmlrule. The tool skips at-rule preludes on purpose. - Turning hairlines into rem. A
1pxborder as0.0625remmay render blurry or vanish at some zoom levels. Keep small values in px with the "Keep px up to" field. - Confusing em with rem.
emcompounds: a1.2eminside another1.2emis bigger than it looks. Useremfor predictable sizes,emwhen the size should follow the component. - Typing a unit in the value field. Type only
24, then pick px in "Unit". Text such as24pxis not a valid number and shows an error. - Setting the root to zero. Font sizes must be above zero. Until you fix it, the tool uses 16 px and says so.
Frequently asked questions
How do I convert px to rem?
Divide the pixels by the root font size. With 16 px, 20 px divided by 16 is 1.25rem. The tool does this for one value or for a whole stylesheet.
What does the 62.5% trick do?
It sets html { font-size: 62.5%; }, so the root becomes 10 px and 1rem equals 10 px. Set the root to 10 here to convert accordingly. You then usually restore body text with body { font-size: 1.6rem; }.
Is rem better than px for accessibility?
Usually yes for text and spacing, because it respects the font size the user chose. Borders and shadows are fine in px. For other conversions, such as meters or kilograms, try the unit converter.
Where do I go next?
If your CSS has hard-coded colors and gradients, the CSS gradient generator helps, and the CSS to React style converter turns the result into a style object.