PX to REM converter

PX to REM for Tailwind CSS

Tailwind's spacing and font-size utilities are written in rem. With the browser's default root font size of 16px, every spacing step is 0.25rem (4px), so p-4 is 1rem or 16px and mt-6 is 1.5rem or 24px.

Use the converter below for any value, or the tables to go straight from a pixel size in a design to the Tailwind class.

Convert a value

1rem = 16px · 24px = 1.5rem

Common sizes at 16px

PixelsREM
1px0.0625rem
2px0.125rem
4px0.25rem
6px0.375rem
8px0.5rem
10px0.625rem
12px0.75rem
14px0.875rem
15px0.9375rem
16px1rem
18px1.125rem
20px1.25rem
22px1.375rem
24px1.5rem
28px1.75rem
32px2rem
36px2.25rem
40px2.5rem
48px3rem
56px3.5rem
64px4rem
72px4.5rem
80px5rem
96px6rem
128px8rem

Convert a whole stylesheet

Direction
Converted (8 values)
.card {
  padding: 1.5rem 2rem;
  margin-bottom: -0.5rem;
  border: 1px solid #dde3d9;
  border-radius: 0.75rem;
  font-size: 1.125rem;
  line-height: 1.75rem;
  background: url("icons/arrow-16px.svg");
}

@media (min-width: 48rem) {
  .card { max-width: 40rem; }
}

Spacing scale: px, rem and Tailwind class

Applies to padding (p-), margin (m-), gap (gap-), width and height (w-, h-), inset and more. The class number is the pixel value divided by 4.

pxremTailwind
2px0.125remp-0.5
4px0.25remp-1
6px0.375remp-1.5
8px0.5remp-2
10px0.625remp-2.5
12px0.75remp-3
14px0.875remp-3.5
16px1remp-4
20px1.25remp-5
24px1.5remp-6
28px1.75remp-7
32px2remp-8
36px2.25remp-9
40px2.5remp-10
44px2.75remp-11
48px3remp-12
56px3.5remp-14
64px4remp-16
80px5remp-20
96px6remp-24

Font sizes

pxremTailwind
12px0.75remtext-xs
14px0.875remtext-sm
16px1remtext-base
18px1.125remtext-lg
20px1.25remtext-xl
24px1.5remtext-2xl
30px1.875remtext-3xl
36px2.25remtext-4xl
48px3remtext-5xl
60px3.75remtext-6xl
72px4.5remtext-7xl
96px6remtext-8xl
128px8remtext-9xl

Sizes that aren't on the scale

For a value like 18px padding, use an arbitrary value. Writing it in rem keeps it consistent with the rest of Tailwind and lets it scale with the user's font size: p-[1.125rem] rather than p-[18px].

If a design uses an odd size in many places, give it a name in your theme instead. In Tailwind v4, add --spacing-card: 1.125rem; inside @theme to get p-card, gap-card and so on; in v3, add card: "1.125rem" to theme.extend.spacing in tailwind.config.js.

If your root font size isn't 16px

Every rem value is relative to the html font size. If a project sets html { font-size: 62.5%; } (10px), p-4 becomes 10px instead of 16px. Set the root font size in the converter to match, and keep in mind that it changes every Tailwind size at once.

Frequently asked questions

How many pixels is p-4 in Tailwind?

16px. p-4 is 1rem, and 1rem is 16px at the browser's default root font size. Each step on the spacing scale adds 0.25rem (4px).

Why does Tailwind use rem instead of px?

rem sizes follow the user's browser font-size setting, so text and spacing grow together for people who increase it. px sizes stay fixed.

How do I convert px to a Tailwind class quickly?

Divide the pixel value by 4 for spacing: 24px is 6, so p-6, m-6 or gap-6. For font sizes, use the table above.

From the blog