PX to REM Converter
Convert px to rem and em with any root font size, build a bulk conversion table and turn every px value of a CSS snippet into rem in one click.
em is relative to the font size of the parent element, rem to the root (html) element.
Convert a value
Bulk conversion table
| px | rem | em |
|---|
Convert a CSS snippet
How to use the PX to REM converter
- Set the Root font size (px). It is 16 in every major browser unless your stylesheet changes it. The buttons under the field switch to 16 px, 10 px (the
html { font-size: 62.5%; }trick) or 18 px. - If you work with em, set the Parent font size for em (px): the computed font size of the element that contains the one you are styling.
- Under Convert a value, type in Pixels (px), REM or EM. The two other fields update as you type, and the line below shows the division used.
- The Bulk conversion table lists common sizes. Replace the Pixel values with your own design tokens (spacing scale, type scale…) and use Copy table to paste the result into a spreadsheet or a design document.
- To migrate existing code, paste it into CSS to convert, choose the options and click Convert px to rem. Load an example shows a small stylesheet. Copy the Converted CSS with Copy.
The formulas
- rem = px ÷ root font size. With the default 16 px, 24px = 24 ÷ 16 = 1.5rem.
- em = px ÷ parent font size. Inside a 20 px heading, 10px = 0.5em.
- px = rem × root font size, and px = em × parent font size.
rem vs em: which one to use?
rem (“root em”) always refers to the font size of the html element, so 1.5rem means the same thing everywhere on the page. It is the safest choice for font sizes, spacing, max-widths and layout gaps.
em refers to the font size of the element itself (for font-size, the parent’s). It compounds: a list at 0.9em nested three times ends up at 0.9 × 0.9 × 0.9 = 73 % of the base. That makes em handy for things that should scale with their own text (the padding of a button, the size of an icon next to a label) and risky for global typography.
Why rem matters for accessibility
Many people raise the default font size in their browser settings (for example from 16 to 20 or 24 px) instead of zooming every page. Sizes written in px ignore that preference; sizes in rem or em follow it. Using rem for text and spacing lets the whole layout grow with the reader’s choice, which helps with WCAG 2.2 success criterion 1.4.4 (resize text up to 200 %).
For the same reason, avoid setting html { font-size: 16px; } in px: use a percentage (100%, or 62.5% if you want 1rem = 10px) so the user’s setting still applies.
What the CSS converter changes
It replaces numbers followed by px in declarations with the value divided by the root font size. It never touches comments, strings or url() values.
- Keep border and outline widths in px:
border,border-*-width,outline,outline-offsetandcolumn-rulestay in px, so thin lines stay crisp.border-radiusis still converted. - Keep 1px values: any value between −1px and 1px stays as it is.
- Convert media queries to em (16px base): in
@mediaconditions, rem and em always refer to the browser’s initial font size, never to yourhtmlrule, so the tool divides by 16 and writes em there, whatever your root size. When unchecked, media queries keep their px.
Frequently asked questions
How many pixels is 1rem?
16 px by default. If your stylesheet sets html { font-size: 62.5%; }, 1rem = 10 px, and it grows if the user raises the browser’s default font size.
Is rem the same as em?
Only on elements whose parent uses the root font size. rem always looks at the html element; em looks at the parent, so nested em values multiply.
Should I convert borders to rem?
Usually not. A 1px border converted to 0.0625rem can render blurry or disappear on some screens at unusual font sizes. That is why the border and 1px options are on by default.
Does zooming the page make rem useless?
No. Browser zoom scales px and rem alike, but the default font size setting only scales relative units. Supporting both is part of respecting the reader’s preferences.
Is my CSS sent anywhere?
No. The conversion runs entirely in your browser and nothing you paste leaves your device.
Related tools
- Aspect Ratio Calculator Aspect ratio calculator to simplify any width and height, resize while keeping proportions, compare 16:9, 4:3 or 21:9 sizes and copy the CSS aspect-ratio code.
- Font Pairing Previewer Preview font pairings for headings and body text with 20 open-license fonts, adjust size and line height, and copy the CSS font-family stacks.
- CSS Formatter and Minifier Beautify messy CSS with clean indentation or minify it with csso, and see the size before and after. Runs in your browser; nothing is uploaded.
- Box Shadow Generator Design layered CSS box shadows with a live preview. Set offset, blur, spread, color, opacity and inset, try neumorphism presets and copy the code.