px

CSS Unit Converter

Convert between px, rem, em, %, vw, and vh instantly.

📐 Base Font Size: px This is typically set on the html or body element. Default browser value is 16px.
🔄 Enter a value in any field to convert
Pixels
px
Absolute unit, fixed size
Root EM
rem
Relative to root font size
EM
em
Relative to parent font size
Percent
%
Relative to parent element
Points
pt
1pt = 1/72 inch (print)
Viewport Width
vw
1vw = 1% viewport width
📊 Quick Reference (Base: 16px)
Pixels REM EM Points

📖 Complete Guide to CSS Units and Responsive Typography

Understanding CSS units is fundamental to creating responsive, accessible, and well-designed websites. The choice between pixels, rems, ems, percentages, and viewport units affects not only how your designs scale across different devices but also how accessible your content is to users who adjust their browser settings. This comprehensive guide explores each unit type and provides practical guidance for making the right choices in your projects.

The Two Categories of CSS Units

CSS units fall into two fundamental categories: absolute units that represent fixed physical or pixel measurements, and relative units that scale based on other values in the document. Understanding this distinction is crucial because it determines how your designs respond to different contexts.

Absolute units maintain the same size regardless of surrounding context. If you set an element to 16px, it will be 16 pixels wide or tall on any device (accounting for device pixel ratio). Relative units, in contrast, compute their actual size based on another value—the parent element's font size, the root font size, the viewport dimensions, or other references.

Pixels: The Traditional Baseline

Pixels (px) are the most familiar CSS unit, representing the smallest addressable element on a screen. In the early web, pixels provided reliable, predictable sizing. However, the relationship between CSS pixels and physical pixels has become complicated with the advent of high-DPI displays.

Modern browsers interpret CSS pixels as "reference pixels" rather than physical device pixels. A reference pixel is defined as the visual angle of 1/96th of an inch at arm's length viewing distance. On high-DPI (retina) displays, one CSS pixel might correspond to two, three, or more physical pixels. This abstraction ensures that content sized in CSS pixels appears approximately the same physical size across devices with different pixel densities.

When to Use Pixels

Pixels remain appropriate for elements that should maintain fixed sizes regardless of user preferences: thin borders (1-2px), hairline dividers, box shadows, and some decorative elements. They are also useful during development for establishing initial sizes before converting to relative units for production.

When to Avoid Pixels

Avoid pixels for font sizes and spacing in production code. When users adjust their browser's default font size (for accessibility or preference reasons), pixel-based font sizes do not scale. This creates accessibility barriers for users with visual impairments who rely on larger text. Similarly, pixel-based spacing does not scale with text, potentially creating awkward proportions when users increase their font size.

REM: The Accessibility Champion

The rem unit (root em) represents the font size of the root element—typically the html element. In most browsers, the default root font size is 16px, so 1rem equals 16px unless the user or your stylesheet changes this.

The crucial advantage of rem is accessibility. When users increase their browser's default font size (a common accessibility need), all rem-based measurements scale proportionally. A user who sets their browser to use 20px as the base size will see your 1rem text at 20px rather than the typical 16px. All your spacing and sizing scales with this preference, maintaining design proportions while respecting user needs.

The 62.5% Technique

Some developers set the root font size to 62.5% (which equals 10px on default browsers), making mental calculations easier: 1.6rem equals 16px, 2rem equals 20px. However, this technique has drawbacks. It can confuse developers unfamiliar with the convention, and it may interact unexpectedly with third-party styles. Modern development with this calculator makes the math easy enough that the 62.5% technique is often unnecessary.

Using REM for Spacing

Beyond typography, rem units excel for spacing (padding, margin, gap). When users increase their font size, rem-based spacing increases proportionally, maintaining comfortable proportions between text and surrounding space. This creates a more cohesive experience for users who need larger text.

EM: Context-Sensitive Scaling

The em unit is relative to the font size of the element itself (for font-size) or the computed font size of the parent element (for other properties like padding and margin). This context sensitivity makes em powerful but potentially confusing.

The Compounding Effect

The most important thing to understand about em is that it compounds. If you have a parent element with font-size: 1.5em and a child also with font-size: 1.5em, the child's actual font size is 1.5 × 1.5 = 2.25 times the root font size. This multiplication continues with each level of nesting.

Compounding can be useful—creating naturally scaling typography hierarchies—or problematic, leading to unexpectedly large or small text in deeply nested elements. For this reason, many developers prefer rem for font sizes while using em selectively for component-internal spacing.

When EM Shines

Em units are ideal for spacing that should scale with the local font size. Button padding in em creates buttons where the internal spacing remains proportional regardless of the font size. Icon sizing in em keeps icons visually balanced with adjacent text. Component margins in em maintain proportions when components are resized.

Percentages: Relative to Parents

Percentage units are relative to a parent property value. For width and horizontal margins, percentages are relative to the parent's width. For font-size, percentages are relative to the parent's font-size. For height, percentages are relative to the parent's height (if defined).

Percentages are foundational to fluid layouts. A width of 50% creates an element that always occupies half of its container, regardless of the container's size. This responsiveness is why percentages remain essential for layout even with modern tools like flexbox and grid.

Percentage Typography

For font sizes, percentages work similarly to em: 100% equals the parent font size, 150% equals 1.5 times the parent font size. Like em, percentages compound through nesting. Most developers prefer rem over percentages for typography because rem provides a stable reference point regardless of nesting depth.

Viewport Units: Full-Screen Responsiveness

Viewport units (vw, vh, vmin, vmax) are relative to the browser viewport dimensions. One vw equals 1% of the viewport width; one vh equals 1% of the viewport height. Vmin is the smaller of vw and vh, while vmax is the larger.

Use Cases for Viewport Units

Full-screen sections commonly use 100vh to occupy the full viewport height. Hero sections, landing page folds, and modal overlays benefit from viewport-height sizing. Viewport-width sizing helps create full-bleed elements that extend beyond their containers.

Fluid typography using vw creates text that scales smoothly with viewport width. A headline set to 5vw would be smaller on mobile and larger on desktop, maintaining proportional size. However, pure vw typography lacks both minimum and maximum bounds, potentially becoming unreadably small on narrow screens or absurdly large on wide monitors.

The clamp() Function

Modern CSS provides the clamp() function for bounded fluid sizing: clamp(minimum, preferred, maximum). For typography, clamp(1rem, 2.5vw, 2rem) creates text that scales with viewport width but never falls below 1rem or exceeds 2rem. This combines the fluidity of viewport units with the safety of fixed bounds.

Viewport Unit Gotchas

On mobile browsers, 100vh can be problematic because it includes the browser's address bar height. When users scroll and the address bar hides, elements sized at 100vh may appear shorter than intended. The newer dvh, svh, and lvh units (dynamic, small, and large viewport height) address this by accounting for dynamic browser UI, though browser support is still maturing.

Points: The Print Heritage

Points (pt) come from traditional typography, where one point equals 1/72 of an inch. While not commonly used in web design, points occasionally appear in print stylesheets or designs migrated from print-oriented tools.

For screen design, pixels and relative units typically serve better than points. However, understanding the conversion (1pt ≈ 1.333px at 96 DPI) helps when interpreting designs from print-focused tools like Adobe InDesign or when creating print stylesheets.

Choosing the Right Unit

For font sizes, use rem to ensure accessibility and consistent scaling. For component-internal spacing (like button padding), em provides proportional scaling with local font size. For layout dimensions, percentages or viewport units enable responsive sizing. For borders and shadows, pixels provide precise, consistent rendering.

For media query breakpoints, em is often recommended because it scales with user font preferences, triggering responsive breakpoints at appropriate perceptual sizes rather than fixed pixel widths.