CSS Clamp

px to rem converter

Convert between px, rem and vw with any base size.

px ↔ rem

px
=
rem
px
1.5rem

px ↔ vw

px
=
vw
px
3.3333vw

px to rem conversion table

Common values with the default root font size of 16px.

pxrempxrem
1px0.0625rem24px1.5rem
2px0.125rem28px1.75rem
4px0.25rem32px2rem
6px0.375rem36px2.25rem
8px0.5rem40px2.5rem
10px0.625rem48px3rem
12px0.75rem56px3.5rem
14px0.875rem64px4rem
16px1rem72px4.5rem
18px1.125rem80px5rem
20px1.25rem96px6rem

Why convert to rem

A rem is relative to the root font size. When a user raises their browser’s default font size, everything sized in rem grows with it, while pixel values stay the same. Designs are usually made in pixels, so converting is a daily task when you turn a design into CSS.

From units to fluid values

Once you have a mobile and a desktop size, you do not need to pick one. A clamp() value grows from one to the other as the screen gets wider, and mixes rem and vw so it still respects the user’s font size. Enter both sizes in the clamp() generator, or read the maths behind clamp() to see how rem and vw combine.

Frequently asked questions

How do I convert px to rem?

Divide the pixel value by the root font size. With the default root font size of 16px, 24px is 24 / 16 = 1.5rem. To go back, multiply: 1.5rem × 16 = 24px.

What is the default root font size?

Every major browser uses 16px as the default font size, so 1rem is 16px unless the user or your CSS changes it. Users can raise the default in their browser settings, which is exactly why rem is useful: your layout follows their choice.

Should I set html { font-size: 62.5% }?

That trick makes 1rem equal 10px so the maths is easier, but it forces you to reset the body font size and can confuse third-party components that expect 16px. Converting with a tool or a Sass or CSS function is usually the cleaner choice.

How do I convert px to vw?

Divide the pixel value by the screen width and multiply by 100. On a 1440px screen, 48px is 48 / 1440 × 100 = 3.333vw. A vw value alone does not respect zoom or the user’s font size, so combine it with rem inside clamp() for font sizes.

When should I use rem instead of px?

Use rem for font sizes and for spacing that should grow with the text, like padding around paragraphs. Pixels are fine for borders, shadows and other details that should stay sharp and fixed.