REM unit is a mixture of px and em. REM sets the size relative to the root font size of the page. Remember: 1 rem = 16px.
How to Convert PX to REM
To convert pixels to rem, divide the pixel value by the root font size, which is 16px by default in all major browsers. For example, 24px ÷ 16 = 1.5rem, and 12px ÷ 16 = 0.75rem. To convert the other way, multiply: 2rem × 16 = 32px.
The REM unit is always relative to the font size of the root html element, while EM depends on the font size of the surrounding element. That makes REM easier to predict: 1.5rem is the same size everywhere on the page, however deeply the element is nested.
Using REM instead of PX also helps accessibility. When readers increase the default font size in their browser settings, text set in REM grows with it, while text set in PX stays the same.
Some developers set html { font-size: 62.5%; } so that 1rem equals 10px, which makes the math easier. If you do this, set the body font size back to 1.6rem so text doesn’t look too small, and keep in mind that the table below assumes the default 16px.
When to use PX, REM, and EM
Use REM for font sizes, spacing, and layout widths, so the whole page scales with the reader’s settings. EM works well for padding and margins inside a component that should grow with that component’s own text, such as a button. PX still makes sense for details that shouldn’t scale, such as 1px borders and box shadows. In media queries, REM or EM values respond to the reader’s font settings while PX values don’t, so many developers write breakpoints like @media (min-width: 48rem) instead of 768px.
| 10px | 0.625rem |
| 11px | 0.6875rem |
| 12px | 0.75rem |
| 13px | 0.8125rem |
| 14px | 0.875rem |
| 15px | 0.9375rem |
| 16px | 1rem |
| 17px | 1.0625rem |
| 18px | 1.125rem |
| 19px | 1.1875rem |
| 20px | 1.25rem |
| 21px | 1.3125rem |
| 22px | 1.375rem |
| 23px | 1.4375rem |
| 24px | 1.5rem |
| 25px | 1.5625rem |
| 26px | 1.625rem |
| 27px | 1.6875rem |
| 28px | 1.75rem |
| 29px | 1.8125rem |
| 30px | 1.875rem |
| 31px | 1.9375rem |
| 32px | 2rem |
| 33px | 2.0625rem |
| 34px | 2.125rem |
| 35px | 2.1875rem |
| 36px | 2.25rem |
| 37px | 2.3125rem |
| 38px | 2.375rem |
| 39px | 2.4375rem |
| 40px | 2.5rem |
| 41px | 2.5625rem |
| 42px | 2.625rem |
| 43px | 2.6875rem |
| 44px | 2.75rem |
| 45px | 2.8125rem |
| 46px | 2.875rem |
| 47px | 2.9375rem |
| 48px | 3rem |
| 49px | 3.0625rem |
| 50px | 3.125rem |
| 51px | 3.1875rem |
| 52px | 3.25rem |
| 53px | 3.3125rem |
| 54px | 3.375rem |
| 55px | 3.4375rem |
| 56px | 3.5rem |
| 57px | 3.5625rem |
| 58px | 3.625rem |
| 59px | 3.6875rem |
| 60px | 3.75rem |
| 61px | 3.8125rem |
| 62px | 3.875rem |
| 63px | 3.9375rem |
| 64px | 4rem |
No comments yet — be the first