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 | Tailwind unit |
|---|---|
| 4px | 1 |
| 8px | 2 |
| 12px | 3 |
| 16px | 4 |
| 20px | 5 |
| 24px | 6 |
| 32px | 8 |
| 40px | 10 |
| 48px | 12 |
| 64px | 16 |
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.
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.
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.
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.
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.