PX to Tailwind Converter

Convert pixels to Tailwind CSS spacing units, where one unit equals 0.25rem (4px at the default base). Instead of guessing whether 24px is p-6, the tool maps your pixel value straight to the nearest Tailwind class number. The table below lists the common pixel-to-Tailwind mappings.

Pixels to Tailwind spacing units (1 unit = 4px)

PixelsTailwind unit
4px1
8px2
12px3
16px4
20px5
24px6
32px8
40px10
48px12
64px16

When to use it

  1. Translate a pixel spec into Tailwind spacing classes like p-4 or gap-6.
  2. Match a design's pixel grid to Tailwind's 4px scale.
  3. Find the closest Tailwind unit for an arbitrary pixel value.

How to Use

  1. Type a pixel value into the PX field — for example, 16.
  2. The Tailwind unit number appears in the Tailwind field, plus the suggested class (w-4 for 16px).
  3. If your value isn't on the scale, the class field stays blank — round up or use an arbitrary value.
  4. Use the reference table to see the full Tailwind spacing scale at a glance.
  5. Copy either field with one click into your component file.

Features

  1. Maps pixel values directly to Tailwind's official spacing scale
  2. Shows the suggested class (w-4, w-8, etc.) for exact matches
  3. Full Tailwind scale reference table from 0 to 96
  4. Bidirectional — type px or scale unit, the other updates
  5. 100% browser-side — never uploads your design data

FAQs

How does Tailwind's spacing scale work?

Tailwind's spacing scale is 4-based: 1 unit = 0.25rem = 4px (at the default 16px root). So w-1 = 4px, w-2 = 8px, w-4 = 16px, w-8 = 32px. The scale extends through w-96 (384px) with key fractional values (w-0.5 = 2px, w-1.5 = 6px) for finer adjustments. This calculator gives you the exact Tailwind class for any pixel value, plus the closest match for values not directly on the scale.

What if my pixel value isn't on the Tailwind scale?

Tailwind's scale has gaps — there's no class for 5px, 7px, 13px, 22px, etc. For those values you have three options: round to the nearest scale value (often acceptable in design), use an arbitrary value like w-[13px] (Tailwind 3+ supports this), or extend the scale in your tailwind.config.js. This calculator shows the exact class only when there's an exact match — otherwise the class field stays blank, signaling you need one of those workarounds.

Why use Tailwind class names instead of raw pixels?

Consistency across the codebase. When everyone uses w-4 instead of width: 16px, the design system stays enforced automatically — you can't accidentally type 15px. Tailwind also produces smaller CSS because every class is reused (purged) rather than generating unique inline values. Plus, the scale itself is opinionated toward visually-pleasing values, which removes a category of design decisions.

Does this work for margin, padding, gap, and width?

Yes — Tailwind uses the same spacing scale for m-*, p-*, gap-*, w-*, h-*, top-*, left-*, etc. The class prefix changes but the number value maps the same way. So 16px is w-4, p-4, m-4, gap-4, h-4, top-4 — all 4 in the spacing scale. The class shown here uses w- as a convenient example; substitute the prefix you need.

Technical Details

Tailwind CSS uses a spacing scale where 1 spacing unit = 4px (so w-4 = 16px, p-2 = 8px). Conversion is straightforward: Tailwind units = px / 4. The tool also shows the corresponding Tailwind class name (e.g., w-{n}) for exact scale matches. The full Tailwind v3 spacing scale is hardcoded in a lookup table, enabling instant class identification for any pixel value on the scale.

Calculators & Converters

Calculators & Converters

  • Tailwind to PX Converter
  • Golden Ratio Calculator
  • Cost Estimation Calculator
  • Universal Converter
  • Notepad Calculator
  • Mileage Calculator
  • Land Area Converter (Marla, Kanal, Acre)
  • Tire Size Calculator