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.
| px | rem | Tailwind |
|---|---|---|
| 2px | 0.125rem | p-0.5 |
| 4px | 0.25rem | p-1 |
| 6px | 0.375rem | p-1.5 |
| 8px | 0.5rem | p-2 |
| 10px | 0.625rem | p-2.5 |
| 12px | 0.75rem | p-3 |
| 14px | 0.875rem | p-3.5 |
| 16px | 1rem | p-4 |
| 20px | 1.25rem | p-5 |
| 24px | 1.5rem | p-6 |
| 28px | 1.75rem | p-7 |
| 32px | 2rem | p-8 |
| 36px | 2.25rem | p-9 |
| 40px | 2.5rem | p-10 |
| 44px | 2.75rem | p-11 |
| 48px | 3rem | p-12 |
| 56px | 3.5rem | p-14 |
| 64px | 4rem | p-16 |
| 80px | 5rem | p-20 |
| 96px | 6rem | p-24 |
Font sizes
| px | rem | Tailwind |
|---|---|---|
| 12px | 0.75rem | text-xs |
| 14px | 0.875rem | text-sm |
| 16px | 1rem | text-base |
| 18px | 1.125rem | text-lg |
| 20px | 1.25rem | text-xl |
| 24px | 1.5rem | text-2xl |
| 30px | 1.875rem | text-3xl |
| 36px | 2.25rem | text-4xl |
| 48px | 3rem | text-5xl |
| 60px | 3.75rem | text-6xl |
| 72px | 4.5rem | text-7xl |
| 96px | 6rem | text-8xl |
| 128px | 8rem | text-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.