CSS Unit Converter

Convert between px, rem, em, %, vw, vh, and more CSS units.

Convert CSS Units

1.0000

Conversion Settings

px
px
px
px
px

💡 Pro Tip

Use rem for font sizes to respect user preferences. Use em for component-relative spacing.

More Design Tools

The Science of Responsive Web Sizing

Modern web design has moved far beyond the rigid pixel. To build interfaces that adapt seamlessly from smartwatches to 8K monitors, developers rely on a complex ecosystem of relative units. Our CSS Unit Converter bridges the gap between the absolute predictability of pixels and the flexible power of relative units like REMs, EMs, and Viewport percentages.

Decoding CSS Lengths

Relative Units

SCALABLE & ACCESSIBLE
  • rem: The gold standard. Relative to the root html font size (usually 16px). Use this for almost everything.
  • em: Relative to the parent element. Great for components where padding should scale with the local font size.
  • ch: Relative to the width of the "0" character. Perfect for readable max-width text columns.

Viewport Units

FLUID & DYNAMIC
  • vw/vh: 1% of the Viewport Width/Height. 100vh makes full-screen hero sections easy.
  • vmin/vmax: The smaller or larger dimension of the viewport. Good for orientation-independent sizing.
  • dvh: Dynamic Viewport Height. Solves the mobile browser "URL bar jump" issue.

Absolute Units: When to Use Them?

Pixels (px) are not dead

While accessibility advocates push for REMs, Pixels still have a place. They are "absolute" in the CSS world (1px = 1/96th inch), enabling precise control.

Good For
  • Borders (1px hairline)
  • Shadow offsets
  • Canvas sizing
  • Generic padding
Bad For
  • Main Font Sizes (Accessibility issues)
  • Container widths (Responsive issues)
  • Media Query breakpoints (Zoom issues)

The "62.5%" Trick Explained

Many developers dislike calculating that 14px / 16px = 0.875rem. A popular workaround is setting the html font size to 62.5%.

html {
font-size: 62.5%; /* 16px * 0.625 = 10px */
}
body {
font-size: 1.6rem; /* Becomes 16px */
}

Now, 1rem equals 10px, so 1.4rem is 14px, 2.4rem is 24px, etc. The math becomes trivial, but you still keep the accessibility benefits of relative units!

Frequently Asked Questions

Why is REM better than PX for accessibility?

REM (Root EM) units are relative to the user's browser font size setting (default 16px). If a user with visual impairments increases their browser's default font size to 24px, a website built with REMs will scale up proportionally. A website built with fixed PX values will strictly stay at the hardcoded pixel size, ignoring the user's preference and potentially making the text unreadable.

What is the difference between EM and REM?

REM is relative to the root element (html), giving you a consistent global sizing system. EM is relative to the parent element. This means EMs can compound: a 2em font inside a 2em container becomes 4em relative to the root. EMs are great for component-level modularity (like padding scaling with font size), while REMs are better for global layout and typography.

How do I calculate PX to REM manually?

The formula is Target PX / Root Font Size = REM. Assuming the standard root size is 16px:

  • 16px = 1rem
  • 24px = 1.5rem
  • 32px = 2rem. Most developers set the root font size to 100% (default) but some use the '62.5% trick' (setting html size to 10px) to make math easier (so 1.4rem = 14px), though this is debated in modern development.
When should I use Viewport Units (vw/vh)?

Viewport units are powerful for layouts that need to adapt to the window size, not just the content. 100vh is perfect for full-screen hero sections. vw is great for fluid typography that scales seamlessly from mobile to desktop. However, use them carefully for font sizes, as text can become too small on mobile or too massive on ultrawide monitors without clamping.

What is the 'ch' unit?

The ch unit represents the width of the character '0' (zero) in the current font. It is incredibly useful for setting max-widths on text containers to ensure optimal readability. Research suggests standard reading lines should be 45-75 characters long. Setting max-width: 65ch creates this perfect typographic measure automatically.

Does this tool support high-DPI (Retina) displays?

CSS pixels are actually 'logical' pixels, not physical device pixels. On a high-DPI screen (like a Retina display), 1 CSS pixel might equal 2, 3, or even 4 physical hardware pixels. Our converter deals with standard CSS units, which is exactly what you need for writing stylesheets, regardless of the screen density.

What are container queries (cqw, cqh)?

Container query units are the evolution of responsive design. While vw/vh relate to the viewport, cqw/cqh relate to a specific parent container marked as a query container. This allows you to build truly modular components (like a card) that look good whether they are in a narrow sidebar or a wide main content area.

Can I use decimals in pixel values?

Yes, modern browsers support sub-pixel rendering (e.g., 14.5px). However, the result depends on the screen technology. Some engines might round to the nearest whole pixel, while others use anti-aliasing to simulate the fraction. For consistent, predictable layouts, it's often safer to stick to whole pixels or use flex/grid for distribution.

What is existing Pt (Point) unit used for?

Points (pt) are a print-centric unit where 72pt = 1 inch. In web design, they are rarely used for screen layouts but are crucial when creating Print Stylesheets (@media print). If you want your web page to print perfectly on physical paper, define your print styles using pt, cm, or in.

Why does my 100vh element scroll on mobile?

On mobile browsers (like Safari iOS), the URL bar comes and goes, changing the viewport height dynamically. A heavily debated issue is that 100vh often includes the area covered by the URL bar, causing content to be cut off. The solution is using the new dynamic viewport units: dvh (Dynamic Viewport Height), lvh (Large), and svh (Small) to handle these UI states correctly.