Px to Rem Conversion: CSS Unit Math With Examples
Last updated: · 4 min read
Design files usually give sizes in pixels, but an accessible website should describe text sizes in rem or em, so that the page grows when a visitor raises the default text size in the browser. This guide explains the formula that converts pixels to rem and em, why the root font size is the key value, and where the point (pt) equivalent comes from. The values in the example are the real output of the Px to Rem / Em Converter.
Formula
rem = px ÷ root font size (default 16 px) px = rem × root font size em = px ÷ parent font size (the tool assumes the parent equals the root size) pt = px × 0.75 (in CSS, 1 px = 1/96 inch and 1 pt = 1/72 inch)
rem scales with the font size of the root (html) element, while em scales with the font size of the element it is used in. The CSS Values and Units Level 4 specification defines the reference pixel as 1/96 inch; since a point is 1/72 inch, one point equals 0.75 px. The tool assumes the parent element has the same size as the root for em, so nested elements can give different real results.
What the inputs mean
- Value
- The number to convert. For px → rem / em, enter the pixel value; for rem / em → px, enter the rem or em value (for example 24 or 1.5).
- Root font size
- The font size of the html element in pixels. The browser default and most design systems use 16 px; change this value if your site sets a different root size.
- Direction
- “px → rem / em” or “rem / em → px”. Use it to move from a design file to code or the other way round.
Worked example: The rem equivalent of 24 px
- Input: 24 px, root font size 16 px, direction px → rem / em.
- rem = 24 ÷ 16 = 1.5. The tool gives the same result: 24 px = 1.5 rem.
- For em, if the parent is 16 px, the result is again 1.5: 24 px = 1.5 em (when the parent is 16 px).
- The point equivalent is 24 × 0.75 = 18: 24 px = 18 pt.
- In the reverse direction, 1.5 rem = 1.5 × 16 = 24 px confirms the calculation.
Result: Tool output: 24 px = 1.5 rem, 24 px = 1.5 em (when the parent is 16 px) and 24 px = 18 pt. With a 16 px root, every rem equals 16 px.
How to read the result
Defining text sizes in rem keeps the visitor's browser text preference, which fits the resize principles of WCAG. Using px for fine details such as borders and shadows is perfectly acceptable. Use em with care inside nested elements, because it multiplies at each level.
Common mistakes
- Assuming a 16 px root in a design that changed it. If the root font size is set differently in CSS, all rem results change.
- Treating em and rem as the same. rem is based on the root, em on the parent element, so the difference grows inside nested components.
- Mixing pt and px. For print, pt is common; on screen 1 pt is 1.333 px, so 24 px is 18 pt, not 24 pt.
- Rounding too early. Keep values like 1.333 with several decimal places, and use the exact value in the design file.
- Converting every size to rem, including borders. Thin lines and spacing are often clearer in px; this is a design decision, not a rule.
Frequently asked questions
What is the difference between rem and em?
rem always scales with the root element's font size. em scales with the font size of the element where it is used, which is why rem is more predictable.
What if my root font size is not 16 px?
Enter the actual value: with a 20 px root, 24 px equals 1.2 rem. The result depends only on the root size you enter.
Why is the pixel described as 1/96 inch?
In CSS the reference pixel is defined as 1/96 inch. Physical pixels differ by device, but this reference stays fixed.
Does the tool store the values I enter?
The conversion runs in your browser on the page, and the inputs are not sent to a server.
The result is not exact or binding and is for information only; it is not an official document and cannot be used in official procedures. Confirm it with the competent authority or a professional before acting; no liability is accepted for losses arising from its use.