Cookies This site keeps only what it needs to work. There is no analytics and no advertising on it today, and nothing here follows you to other sites. Read the privacy policy

Choose what to allow
+92 312 8299940Free Quote
EN – Language: English
Blog

Rem vs Px in CSS Which to Use for Text and Why

Rem vs px in CSS: the real difference for text size, accessibility, when to use each unit, and a px to rem conversion table.

By Daniyal Subhani 9 min read

What px and rem Actually Are: Rem vs px

One px is equal to one physical pixel. 16 px is always 16 pixels. This makes it very precise. But, pixels are only as big as the monitor they’re being viewed on and can vary from screen to screen. Because of this, px can be unreliable and hard to work with.

Rem vs Px in CSS
Rem vs Px in CSS

A rem is relative to the font-size of the root element. Since the root element is the html element, 1rem = 16px. A size of 2rem would mean 32px. Likewise, 0.5rem would be 8px.

The biggest difference happens with a user's change of settings. If a user increases their browser's default font size to improve readability, then everything on your web page increases as well. Text measured in px remains unchanged. As a result, elements may look distorted and cracky to the user. On the other hand, text measured in rem scale so.

Why rem Matters for Accessibility

Many users change their browser's default font size in order to be able to read text on the web. So, having small fonts is really a hindrance to a majority of users.

When you size text in rem, you respect that choice. A user who bumps their default from 16px to 20px sees your whole site's text grow proportionally, staying readable. When you size text in px, you override their choice. Your `14px` body text stays 14px no matter how large they set their default, leaving them squinting.

This is why accessibility guidelines favor relative units for text. Using rem isn't just tidy. it's the difference between a site that adapts to a user's needs and one that fights them. For anyone who cares about reaching all their users, that's reason enough to default to rem for font sizes.

When to Use rem

Reach for rem whenever scaling with the user's preference is a good thing. That covers most of your layout.

body text should surely be measured in rem to give users the ability to resize text to their preference.

Use rem for spacing like padding and margin. Your whitespace scales with the text and the layout stays balanced when someone enlarges the font.

Use rem for widths and max-widths on text containers. A readable line length holds up as text grows.

Use rem for media query breakpoints if you want your layout to respond to the user's font size, not just the screen width. This is a more advanced touch. A nice one.

When to Use px

px still has legitimate jobs. Use it where a fixed size is genuinely correct.

Use px for borders. A `1px` border should usually stay crisp and hairline-thin regardless of font size. Scaling a border rarely looks good.

Use px for fine details like a small box-shadow offset or a precise icon alignment, where you want an exact, unchanging value.

Use px for things that shouldn't scale with text, like a fixed-size decorative element whose dimensions are tied to an image, not to the reading experience.

Mostly speaking, use rems to define dimensions related to font size. Use px to define other dimensions.

The Conversion Table

Converting px to rem is easy since the default value is 16px. Divide the px value by 16 to get the rem value.

PixelsRemCommon use
4px0.25remTiny spacing
8px0.5remSmall gap
12px0.75remSmall text
16px1remBase body text
20px1.25remLarge text
24px1.5remSmall heading
32px2remHeading
48px3remLarge heading
64px4remSection spacing

A trick some coders use is to set the font-size of the root element to 62.5%. With this, 1rem would equal 10px. So 1.6rem would be equivalent to 16px. Doing this can be useful for quick conversions. Some coders don’t advise this as it may complicate things if forgotten. It’s a personal preference.

A Real-World Example

Now imagine you build a site and set all measures in px: body text at 14px, headings at 20px, captions at 10px. A visitor to the site with low vision and a large choice of site measures set to the browser default of 24px comes to your site. What they see may not be what you designed.

When a user goes to change the text size on your px-based site, nothing happens. Your 14px text stays at 14px and the user either gives up or leaves the site. Now, let’s say you used body { font-size: 0.875rem } and headings { font-size: 1.25rem } and captions { font-size: 0.625rem }… That user could set their default text size to 24px and your whole site would scale so. Now your body text is 24px and your headings are huge and unbalanced. Same design, but one served the user and the other excluded the user.

That’s the main reason experienced coders use rem by default.

How to Work With These Units

It’s fairly simple to switch a design from px to rem, you just have to divide the px size by 16. Many browser extensions and build tools do this on its own. To check the accessibility of your text, use an online contrast checker.

For the formal specs, [MDN's guide to CSS values and units](here explains every unit in depth. The [W3C's accessibility guidance](here covers why resizable text matters. The free [Denwix tools](here can help with related web checks.

The Bottom Line

Rem vs px comes down to flexibility versus fixedness. px is absolute and never changes, while rem scales with the user's font-size preference, which makes it the accessible choice for text, spacing. Layout. Default to rem for anything about reading or proportion, keep px for crisp borders and fixed visual details. Use the divide-by-16 rule to change. Build with rem and your site adapts to every user instead of ignoring them.

Questions and Answers

What is the difference between rem and px?

Px is an absolute unit. One px is always the same size. Rem is relative to the root font size. Rem is better for accessibility as it allows users to choose their preferred font size.

What does rem stand for in CSS?

rem stands for "root em." It's sized relative to the font-size of the root html element, which browsers default to 16px. @CAP@1rem equals 16px unless you change the root.

Should I use rem or px for font size?

Use rem to define font sizes to allow users to increase the size of the text on your site to their preferred setting. Users who need larger default font sizes will see your site at larger sizes.

Why is rem better for accessibility?

Because rem sizes scale with the user’s default font size. When a user increases the default font size on the browser to increase legibility, text with px sizes remain small and unreadable.

When should I use px instead of rem?

Use px for sizes of non-text elements, like 1px borders. A thin shadow should remain 1px, no matter the font size.

How do I convert px to rem?

Divide the px value by the root font-size, normally 16. So 16px is 1rem, 24px is 1.5rem, and 8px is 0.5rem. The division gives you the rem equivalent.

What is 1rem in pixels?

Initially, 1rem is equivalent to 16px because that is the initial value of the root element’s font size.

Is rem relative to the parent element?

Rems are relative to the root element's font size. This makes rems predictable and easier to work with. Ems compound through nested elements like ems.

What is the difference between rem and em?

Like ems, rems are relative to font size. but, rems are relative to the root element only. Ems are relative to the element or parent element's font size.

Can I mix rem and px in the same stylesheet?

Yes, and good CSS practice is to do the same. The use of rems for elements' dimensions and spacing is very common and encouraged. Pixels should be used to define the dimension of borders to retain sharp edges.

Does using rem affect performance?

Not really. The browser will instantly interpret both. There won't be a measurable difference. So speed shouldn't be a factor in your choice.

What is the 62.5% trick with rem?

Setting the root font size to 62.5% makes 1rem equal to 10px. So, for conversions, just remember that 1rem is equal to 10px. Many coders like doing this because it gives them an easy way to find dimensions in pixels. But, this can be confusing if you forget you set it.

Should spacing use rem or px?

rem is better for margin and padding. That means as text is enlarged, whitespace increases as well, keeping the overall design in better balance.

Do media query breakpoints use rem or px?

Both work. Breakpoints using px respond to the width of the screen only. Breakpoints using rem respond to many sizes of text used by the user and give a better layout for accessibility and usability.

Why does my text not resize when I use px?

That's because px is absolute and ignores the browser's default font size. Use rem and your text will be easier to read for the user because they can increase the size to their preference.

Is px bad for web design?

No, px should be used for exact values such as aligning elements to the edge of a border. Using px for text makes it hard for users to change the size to what is comfortable for them to read.

What unit should headings use?

Sizing headings in rem keeps them at a relative size to body text and readable at any default browser size.

How do I keep borders crisp with rem text?

Use px to set the border width of elements. Use rem to set the size of text and spacing. A thin 1px border remains crisp. Using rem for text and spacing allows content to scale with the user’s preference.

Does rem work in all browsers?

Yes. rem has been widely supported in browsers for many years. You don't have to worry about browser compatibility when using rem.

What's the best default unit for a new project?

Rem should be the default measure to establish baseline accessibility. Use px to set the width of borders and other fixed measures. Use rem to set the size of text and spacing to establish a good baseline of accessibility for the site from the start, as opposed to adding it later.

What unit should I use for borders?

Use px to set the width of a border to get a crisp 1px line. Using rem would result in a thicker line that wouldn’t be as easy to read.

Does rem affect page load speed?

No. Both rem and px are handled instantly by the browser with no measurable performance difference. Choose based on accessibility and flexibility, not speed.

How do I convert 18px to rem?

Divide by 16 since that is normally the square root of the font size. So 18px is 1.125rem. This holds true for any value. Pixels divided by 16 give the rem equivalent.

Can I use rem for media queries?

Yes. Breakpoints set in rem are more accessible since they respond to the user’s preferred font size in addition to the width of the user’s window.

Is em the same as rem?

No. em is relative to the element’s or parent element’s font size and so compounds when nested. rem is relative to the root element and so stays steady.

What happens to rem if the user zooms?

Pixels do not respond to a user's preferred font size the way rem does. Both rem and px affect accessibility.

Should buttons use rem or px?

Use rem for button padding and text to give accessibility. Use px for things like sharp borders to give the user the most control over the interface.

Why is my rem sizing off?

Make sure to check if you modified the root font size. If you set it to anything other than the default of 16 px, things may be unexpectedly large or small to the user.

Video guide

Video Guide: Rem vs Px in CSS

This brief video shows each step from start to finish. Choose your language below, and switch on captions if they help.

Try It in Your Browser

Open the free PX to REM Converter and do it now, right in your browser.

Prefer Denwix on GoogleReview Denwix on Google