PickCode Add to Chrome
  1. Home
  2. Answers
  3. Tailwind px to rem

How do Tailwind classes convert between px and rem?

Updated October 29, 2026

Short answer

Tailwind sizes are in rem, and with the default 16px root font size 1rem equals 16px. Each spacing step is 0.25rem (4px), so p-4 is 1rem or 16px. To convert a pixel value, divide by 16 for rem, or by 4 for the spacing step: 24px is 1.5rem, which is p-6.

Common conversions

pxremSpacing classText class
40.25p-1
80.5p-2
120.75p-3text-xs
140.875p-3.5text-sm
161p-4text-base
181.125p-4.5 (v4)text-lg
201.25p-5text-xl
241.5p-6text-2xl
322p-8

Why rem and not px

rem follows the user's browser font size setting. Someone who raises their default text size gets bigger text and spacing together, and the layout keeps its proportions. With px, text and spacing stay fixed.

The catch: if a site sets html { font-size: 62.5% }, 1rem becomes 10px there. Copy rem values from such a site into a default project and everything grows by 60%.

Working in px anyway

In Tailwind v4 the whole spacing scale comes from one variable. You can change the base unit, or use an arbitrary value for a single case:

@theme {
  --spacing: 4px;
}

<div class="p-[18px] text-[15px]">...</div>

PickCode maps copied pixel values to the default scale when they match, so 16px of padding becomes p-4. Off-scale values come out as px arbitrary values, and clamp(), vw and % are kept as written.

Full walkthrough: Extract design tokens

Questions

What is p-4 in pixels?

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

Can I make Tailwind use px?

Set --spacing: 4px in @theme in v4, or use arbitrary values. Keeping rem is better for users who change their font size.

Why is my rem value bigger than on the original site?

The original site probably changed the root font size. Check the computed font size of the html element.

Sources

  1. Tailwind CSS: Theme variables
  2. GitHub discussion: px instead of rem in Tailwind
  3. GitHub discussion: rem and root font size
  4. Reddit r/tailwindcss: px to rem

Copy it in one click

PickCode turns any element into Tailwind, React, Blade or HTML + CSS. Free for 5 elements a day.

Add to Chrome

Related