CSS Font-Size Units Explained
Pixels represent absolute, fixed measurements tied to your screen resolution. A 16px font will render identically on every device, but won't respond to user preferences or parent-element sizing. This rigidity makes px useful for precise, non-scaling elements but problematic for accessible, flexible layouts.
Ems are relative units that inherit from their parent's font size. If you set an element to 1.5em and the parent is 16px, the result is 24px. This cascading behavior makes ems powerful for modular components, though nested elements can compound unexpectedly. One em always equals 100% of the inherited size.
Points (pt) are print-industry units where 1 pt equals exactly 0.75 pixels. Web browsers treat 12pt as roughly 16px because traditional print assumes 72 points per inch. Points are rarely used in modern web design but appear in exported PDFs or legacy stylesheets.
Percentages scale relative to the parent element, defaulting to 100% of inherited size. A 150% font size on a 16px parent produces 24px. Percentages and ems behave similarly, making either suitable for responsive designs.
Unit Conversion Formulas
These relationships form the foundation of all CSS unit conversions. The calculations chain together, so converting from one unit type to another requires applying the appropriate formula in sequence.
em = px ÷ base
px = pt ÷ 0.75
px = (percent × base) ÷ 100
pt = em × base × 0.75
percent = (pt ÷ 0.75) × 100 ÷ base
px— Font size in pixelsem— Font size in ems (relative to base)pt— Font size in pointspercent— Font size as percentage of basebase— Base font size, typically 16px for web
Practical Conversion Walkthrough
Suppose you have a design specification in 24pt and need to express it as em values with a base of 16px. First, convert points to pixels: 24pt ÷ 0.75 = 32px. Then divide by the base: 32px ÷ 16px = 2em. Since 1em equals 100%, 2em equals 200%.
Conversely, if you want 1.25em in points using a 16px base, multiply backward: 1.25em × 16px × 0.75 = 15pt. These relationships remain constant regardless of your chosen base size, though changing the base proportionally scales all computed values.
Modern responsive designs typically set base size in pixels (often 16px or 18px) then use em or percentage declarations for scaling components. This hybrid approach preserves absolute control over root typography while allowing sub-elements to adapt flexibly.
Critical Conversion Pitfalls
Avoid these common mistakes when working with CSS units.
- Nested Em Multiplication — Em values compound when nested inside em-sized parents. A 1.2em element inside a 1.2em parent becomes 1.44em relative to the document root, not 1.2em. Always calculate em values relative to their direct parent, not the base.
- Base Size Assumptions — If you don't explicitly set a base size in the calculator, it defaults to 16px—the browser standard. However, users may override this or your site might declare a different base. Always verify your assumption before converting, especially when collaborating with designers using different defaults.
- Point Units in Digital Contexts — Points were invented for print, where DPI is fixed. Browsers render points inconsistently across operating systems and browsers. Avoid using pt for web typography unless exporting to PDF; use px or em instead.
- Percentage Inheritance Chains — Like ems, percentages inherit from parent elements. If a parent is 80% and a child is 50%, the child is actually 40% of the document root. Track the inheritance chain carefully in complex layouts.
When to Use Each Unit
Use pixels (px) for fixed-width elements, borders, and properties that should never scale. Px units work well for consistent spacing or decorative elements unrelated to typography.
Use ems (em) for scalable typography, padding, and margins within components. Ems ensure that spacing scales proportionally with text size, keeping your design systems flexible.
Use percentages (%) for responsive layouts and font sizing when you want inheritance without nesting complexity. Percentages are cleaner in many scenarios because they reset to the base in each new context.
Avoid points (pt) in web layouts. Reserve pt for print stylesheets or PDF generation, where print-industry conventions apply.