How to convert px to rem
Divide the pixel value by the root font size: rem = px ÷ root font size. With the browser default of 16px, 24px is 1.5rem and 8px is 0.5rem. To go back, multiply: px = rem × root font size.
- Set the root font size. Keep 16 unless your stylesheet changes the
font-sizeof thehtmlelement. - Type a value in Pixels or REM; the other field updates as you type.
- To convert a whole stylesheet, paste the CSS into the converter. Every
pxvalue becomesrem, and 1px hairline borders can stay in pixels.
Why use rem instead of px?
- Accessibility: rem values follow the font size people choose in their browser settings. Text and spacing set in px ignore that preference.
- Consistent scaling: change the root font size once and the whole layout scales with it.
- Design systems: Bootstrap and Tailwind CSS both size their spacing and type in rem, so rem values fit right in.
rem vs em
rem is relative to the root (html) font size and means the same everywhere on the page. em is relative to the font size of the current element, so it compounds when elements are nested. Use rem for most sizes and em for things that should scale with their own text, such as the padding of a button or the size of an icon next to a label.
The 62.5% trick
Some projects set html { font-size: 62.5%; } so that 1rem equals 10px and the math becomes easy. It works, but every component then needs its font size reset, and third-party CSS built for 16px renders too small. Keeping the default 16px and using this converter is usually simpler.
Tailwind spacing
Tailwind's spacing scale uses steps of 0.25rem (4px), so p-4 is 1rem and gap-6 is 1.5rem. The table shows the matching number for each common pixel value. Try the converted sizes in our UI components.