Px Em Converter in CSS
? PX to EM Converter in CSS
Pixels (px) and Ems (em) are both CSS units used for sizing, especially fonts and spacing. Converting between them helps build responsive, scalable layouts.
? The Basic Formula
em = target size (px) / base size (px)? Example:
If the base font size is 16px (the browser default), and you want to convert 24px to em:
24px / 16px = 1.5em? Conversion Table (based on 16px base)
| PX | EM |
|---|---|
| 8px | 0.5em |
| 12px | 0.75em |
| 14px | 0.875em |
| 16px | 1em |
| 18px | 1.125em |
| 24px | 1.5em |
| 32px | 2em |
| 48px | 3em |
? CSS Example
html { font-size: 16px; /* Base */}h1 { font-size: 2em; /* 32px */}p { font-size: 0.875em; /* 14px */}?? Want a Quick Converter?
Here’s a simple JavaScript snippet to convert px to em:
function pxToEm(px, base = 16) { return px / base + "em";}console.log(pxToEm(24)); // "1.5em"Would you like a downloadable px?em conversion table or a calculator you can embed on your site?