FA Dev Tools

Pixel Calculator

Convert between Tailwind spacing units, px, and rem. Enter a number with optional unit, or paste CSS (e.g. width: 127.563px; height: 96.546px;).

Width conversions

UnitValueExample class
Tailwind——
Pixels——
REM——

Height conversions

UnitValueExample class
Tailwind——
Pixels——
REM——

Reference

1 Tailwind unit = 0.25rem = 4px

1rem = 16px (default browser font size)

h-4 = h-[1rem] = h-[16px]

Instructions

Converts a size between Tailwind spacing units, px and rem, and gives you the Tailwind class to paste.

  1. Type a size into Width and/or Height. A bare number is read as Tailwind units; add px or rem to say otherwise.
  2. Or paste a CSS declaration into Paste CSS — the width and height are pulled out for you.
  3. Read the conversion tables, and copy the Tailwind class from the top.

Tips

  • The reference numbers: 1 Tailwind unit = 0.25rem = 4px, and 1rem = 16px at the default browser font size.
  • The class to copy is always an arbitrary rem value, such as w-[7.972688rem] for 127.563px, so it works whether or not the size is on the Tailwind scale.
  • Whatever you type is kept in this browser, so the page comes back with your last values.
  • Hit Example, then click Load example for a pasted CSS block, or either size field to fill just that one.

About px, rem and em

What px, rem and em are

px is a fixed CSS pixel. It is not a device pixel: on a high-density screen it covers two or three. rem is relative to the font size of the root element, <html>. em is relative to the font size of the current element, or of its parent when used in font-size itself.

How to convert px to rem

rem = px ÷ root font size. Browsers use 16px by default, so 0.25rem = 4px, 1rem = 16px, 1.5rem = 24px and 13px = 0.8125rem. To go back, multiply: 2rem × 16 = 32px.

pxremTailwind unit
4px0.25rem1
8px0.5rem2
12px0.75rem3
16px1rem4
20px1.25rem5
24px1.5rem6
32px2rem8
48px3rem12
64px4rem16

Why rem helps accessibility

People with low vision often raise the default font size in their browser settings, say from 16px to 20px. Sizes in rem grow with that setting. Sizes in px ignore it, so text set in px stays small. Page zoom scales both. Use rem for font sizes and spacing; keep px for 1px borders.

em compounds

Because em follows the parent, nested values multiply. A list at 0.8em inside another list at 0.8em ends up at 16 × 0.8 × 0.8 = 10.24px. rem avoids this. em is still handy for padding that should scale with the text of a button.

The Tailwind spacing scale

In Tailwind one spacing unit is 0.25rem, which is 4px. So p-1 = 4px and p-4 = 1rem = 16px. For a size off the scale, use an arbitrary value in brackets, such as p-[13px] or w-[0.8125rem]. Tailwind v4 builds the scale from one --spacing variable, so any multiple of 0.25 works, like w-13 or w-2.75; v3 has a fixed list of steps.

Changing the root font size

Some sites set font-size: 62.5% on <html> so that 1rem = 10px and the math is easy. Then you divide by 10, not 16. The catch: Tailwind classes and third-party components shrink too, so p-4 becomes 10px.

What this tool does

It converts a width and a height at once between Tailwind units, px and rem, always with a 16px root. A bare number is read as Tailwind units; add px or rem to say otherwise. em is treated as rem. Paste a CSS block such as width: 127.563px; height: 96.546px; and both values are pulled out. Results keep up to six decimals, and the class to copy is an arbitrary rem value, such as w-[7.972688rem].

Frequently asked questions

How many pixels is 0.25rem?
4px, with the default 16px root font size (0.25 × 16). It is also one Tailwind spacing unit, as in p-1.
How do I convert px to rem?
Divide the pixel value by the root font size, which is usually 16. For example, 24px ÷ 16 = 1.5rem. To convert rem to px, multiply by 16.
Is 1rem always 16px?
No. 16px is only the browser default. It changes when the site sets a font size on the html element, or when the user changes the default font size in the browser settings.