CSS px to rem Converter

Enter a pixel value and the root font size of your page. The converter gives the rem value, and converts a rem value back to pixels.

CSS px to rem Converter

Most browsers start at 16 px. Use the value your stylesheet sets on the html element.

Result

1.5rem

20px

What the CSS px to rem Converter does

The CSS px to rem Converter turns a pixel measurement into a rem measurement, and the reverse. A rem is a length measured relative to the root font size of the page, which is the font size set on the html element. The converter uses the root size you enter to do the arithmetic, so you can plan a stylesheet in pixels and write it in rem.

Designers often sketch layouts in pixels, because that is how graphics tools measure. Writing the stylesheet in rem makes text and spacing scale with the reader's settings, which is one of the most useful habits in responsive web design.

Pixels, rem and em

A pixel is a fixed unit on the screen. A rem is a multiple of the root font size, so 1.5rem is one and a half times the root size. An em is a multiple of the font size of the element it applies to, which can differ from the root size when elements are nested.

The converter shows the em figure next to the rem figure. They are the same only when the element's font size equals the root font size, which is true for many simple elements but not for nested text.

The formula

To convert pixels to rem, divide the pixel value by the root font size. To convert rem back to pixels, multiply the rem value by the root font size. With a root size of 16 pixels, 24 pixels is 24 divided by 16, which is 1.5rem. Conversely, 1.25rem is 1.25 times 16, which is 20 pixels.

The result is rounded to four decimal places, which is enough for any normal stylesheet.

Worked example

A heading designed at 27 pixels on a page with an 18-pixel root size needs 27 divided by 18, which is 1.5rem. If the same page is later given a 20-pixel root size, the heading stays at 1.5rem, which is now 30 pixels, so its size changes with the root rather than being fixed.

That behaviour is the point. A single change to the root size scales the whole layout, while pixel values stay fixed and must be edited one by one.

Choosing the root font size

Most browsers use 16 pixels as their default, and many readers keep that setting. Some sites set the root size to a smaller or larger value, for example to make the text easier to read, and some readers change their browser's default. Keep the root size in one place in your stylesheet and avoid setting it in several rules, so that the conversion is consistent.

Converting in an existing project

Convert gradually. Start with font sizes and spacing that are easy to check, and test the page at several browser text sizes after each change. Check the layout where text is larger, because fixed-width boxes can overflow when rem values grow. Keep a note of the root size used for the conversion, so that future edits follow the same rule.

Limitations

The converter does not know your stylesheet, the nesting of your elements or how your browser applies user preferences. It gives the arithmetic only. Test the result in the browser, especially for text, buttons and forms, where the actual font size of each element matters.

Choosing rem and em for components

For buttons and form fields, em sizes let padding and icons scale with the text inside them, so each component keeps its proportions. For page-wide spacing and headings, rem keeps every section on the same root scale. Mixing the two on purpose, rather than by accident, keeps a design predictable.

Media queries and root size

Some designs change the root font size at certain breakpoints, so every rem value scales for small and large screens. This works well when the change is planned, but it changes every rem value at once, so test each breakpoint and check that nothing overflows.

Testing with text settings

Change the browser's default text size and zoom the page to check the layout. Look for buttons whose labels are cut off, navigation that wraps badly and images that overlap text. Rem sizing helps, but only testing shows the real result.

Line length and readable measure

A comfortable line length depends on the font size, so rem helps keep the measure consistent as text scales. Body text that fills the full width of a wide screen can be hard to read, so constrain the width in characters rather than pixels.

Migrating an older stylesheet

Convert in sections: font sizes first, then spacing, then container widths. Keep a record of the root size used, and review each converted value rather than running a find-and-replace, because some pixel values, such as hairline borders, should stay in pixels.

Keeping values tidy

Round values to sensible steps, such as 0.5rem or 1rem, rather than long decimals. A consistent scale of spacing values is easier to maintain than a collection of unique numbers, and it makes the design easier to change later.

One source for the root size

Set the root font size once, in the rule for the html element, and refer to it from there. Scattered overrides make it hard to know which rem value is in effect, and a change to one rule can ripple unexpectedly through the page.

Choosing rem and em for components

For buttons and form fields, em sizes let padding and icons scale with the text inside them, so each component keeps its proportions. For page-wide spacing and headings, rem keeps every section on the same root scale. Mixing the two on purpose, rather than by accident, keeps a design predictable.

Media queries and root size

Some designs change the root font size at certain breakpoints, so every rem value scales for small and large screens. This works well when the change is planned, but it changes every rem value at once, so test each breakpoint and check that nothing overflows.

Testing with text settings

Change the browser's default text size and zoom the page to check the layout. Look for buttons whose labels are cut off, navigation that wraps badly and images that overlap text. Rem sizing helps, but only testing shows the real result.

Line length and readable measure

A comfortable line length depends on the font size, so rem helps keep the measure consistent as text scales. Body text that fills the full width of a wide screen can be hard to read, so constrain the width in characters rather than pixels.

Migrating an older stylesheet

Convert in sections: font sizes first, then spacing, then container widths. Keep a record of the root size used, and review each converted value rather than running a find-and-replace, because some pixel values, such as hairline borders, should stay in pixels.

Keeping values tidy

Round values to sensible steps, such as 0.5rem or 1rem, rather than long decimals. A consistent scale of spacing values is easier to maintain than a collection of unique numbers, and it makes the design easier to change later.

One source for the root size

Set the root font size once, in the rule for the html element, and refer to it from there. Scattered overrides make it hard to know which rem value is in effect, and a change to one rule can ripple unexpectedly through the page.

Privacy

The values you enter stay in your browser. The converter does not store or send them.

Frequently Asked Questions

Should I use rem or em for font sizes?

Rem is simpler for global sizes because it always refers to the root. Em suits sizes that should scale with their own parent element.

Why is my rem value different from the pixel value on screen?

Because the root font size differs from 16 pixels. Check the font size set on the html element.

Does rem help accessibility?

Yes. Text sized in rem follows the reader's browser text setting, which helps people who need larger type.

What is the conversion for a 10-pixel gap at 16 pixels?

10 divided by 16 is 0.625rem.

Can I use the converter for line heights?

Yes, when the line height is a length. Unitless line heights need no conversion.

By the ToolHuby editorial team. Last updated November 16, 2026.