PickCode Add to Chrome
  1. Home
  2. Free tools
  3. PX to REM converter with Tailwind classes

PX to REM converter with Tailwind classes

Type pixels, rem or a Tailwind step and the other two update. You also get the class to paste, including what changes between Tailwind v3 and v4.

Enter any value
Result
CSS1rem
Spacing, v4p-4
Spacing, v3p-4
Closest on v3 scalep-4 (16px)
Font sizetext-base

Skip the conversion on real pages

PickCode copies any element as Tailwind and maps its pixel values to the default scale when they match. 5 free elements a day.

Add to Chrome, free

How the conversion works

Divide pixels by the root font size to get rem. Browsers default to a 16px root, so 24px is 1.5rem. A Tailwind spacing step is a quarter of a rem, so step 4 is 1rem and 16px.

rem = px / root
step = rem * 4
px = step * 0.25 * root

PX to REM table at a 16px root

PixelsRemSpacing classFont size class
1px0.0625remp-px
2px0.125remp-0.5
4px0.25remp-1
6px0.375remp-1.5
8px0.5remp-2
10px0.625remp-2.5
12px0.75remp-3text-xs
14px0.875remp-3.5text-sm
16px1remp-4text-base
18px1.125remp-4.5 (v4), p-[18px] (v3)text-lg
20px1.25remp-5text-xl
24px1.5remp-6text-2xl
28px1.75remp-7
30px1.875remp-7.5 (v4), p-[30px] (v3)text-3xl
32px2remp-8
36px2.25remp-9text-4xl
40px2.5remp-10
48px3remp-12text-5xl
56px3.5remp-14
60px3.75remp-15 (v4), p-[60px] (v3)text-6xl
64px4remp-16
72px4.5remp-18 (v4), p-[72px] (v3)text-7xl
80px5remp-20
96px6remp-24text-8xl
128px8remp-32text-9xl

Spacing classes use p- here. The same step works with m-, gap-, w- and h-. More on this in how Tailwind converts between px and rem.

What to know

v3 and v4 differ
Tailwind v3 has a fixed list of steps, so 18px needs p-[18px]. Tailwind v4 accepts any multiple of 0.25, so p-4.5 works.
Root size matters
Tailwind's scale is in rem. If a site sets html { font-size: 62.5% }, p-4 is 10px there. Set the root field to 10 to see it.
Font sizes included
When a size matches the default scale you get its name, like text-lg for 18px. Those classes also set a line height.
Stays on your machine
Everything is calculated in this tab. Nothing is uploaded.

Questions

How do I convert px to rem?

Divide the pixel value by the root font size. At the default 16px root, 24px / 16 = 1.5rem.

How many pixels is 1rem?

16px by default, because browsers ship with a 16px root font size. It changes if the user changes their browser font size or the site sets a size on the html element.

What is p-4 in pixels?

16px at the default root: 4 steps of 0.25rem is 1rem.

Should I use px or rem?

Use rem for font sizes and most spacing so they follow the user's font size setting. Keep px for things that should not scale, like 1px borders.

What does 62.5% do on the html element?

It makes the root 10px, so 1.6rem equals 16px. It makes the maths easier but shrinks every Tailwind class to 62.5% of its usual size, because Tailwind expects a 16px root.

Sources

  1. MDN: CSS values and units
  2. Tailwind CSS: padding
  3. Tailwind CSS: font size

More free tools