How to use the px to rem converter
- Choose a mode: px → rem, rem → px or Whole stylesheet.
- Enter values separated by spaces or commas, or paste your CSS.
- Set the root font size (16px in every browser by default) and, for em, the parent’s font size.
- Choose the decimal places, and whether to keep 1px borders in pixels.
- Export the table as CSS custom properties or CSV, the converted stylesheet, or an SCSS
rem()helper.
The formula
rem = px ÷ root font size
em = px ÷ parent font size
With the default 16px root: 24px = 1.5rem, 14px = 0.875rem, 40px = 2.5rem.
Worked examples
Example 1: a spacing scale
Load Spacing scale to convert 2–128px into rem. Paste the CSS variables into your :root and use them everywhere: padding: var(--size-24).
Example 2: converting a legacy component
Load Card CSS. Padding, margins, font sizes and radius become rem, while the 1px border stays crisp in pixels. The box-shadow offsets convert too, which keeps shadows proportional when text is enlarged.
Example 3: breakpoints
Load Breakpoints: 768px becomes 48em and 1024px becomes 64em. In stylesheet mode, breakpoints inside @media are converted to em automatically.
When to keep pixels
- Hairline borders (1px) should stay sharp.
- Shadows and outlines can go either way; rem keeps them proportional.
- Images and icons with fixed artwork sizes often stay in px.
Common mistakes
- Mixing em in nested components. Nested em values multiply; use rem unless you want that.
- Converting
line-heightvalues. Unitless line heights (1.5) are best left unitless. - Hard-coding the root in px. It overrides the visitor’s setting; use a percentage if you must change it.
Testing your converted CSS
After converting, change your browser’s default text size to large in its settings and reload the page. Text and spacing should grow together without overlapping or clipping. Also zoom to 200% and check that nothing needs horizontal scrolling on a normal-width window.