CSS Units Converter

Convert PX, REM, EM, and VH with live desktop and mobile preview.

Desktop

VH
REM + EM {{ cssUnitsPxFromRem().toFixed(2) }}px / {{ cssUnitsPxFromEm().toFixed(2) }}px

Mobile

VH
REM + EM {{ cssUnitsPxFromRem().toFixed(2) }}px / {{ cssUnitsPxFromEm().toFixed(2) }}px

Overview

The original CSS1 specification from 1996 shipped with just six measurement units: `px`, `pt`, `pc`, `cm`, `mm`, and `in` — all absolute, fixed, borrowed from the print world and adapted for the screen. CSS3 dramatically expanded that vocabulary with viewport-relative units like `vw` and `vh`, and `rem` for root-relative sizing. But it was the mobile landscape that forced the creation of the most recent additions: `dvh`, `svh`, and `lvh`, introduced to solve the classic problem of the mobile browser address bar appearing and disappearing as you scroll, breaking layouts that used `100vh` as the full screen height. Today CSS has over 20 measurement units, each with precise semantics and distinct use cases.

In day-to-day practice, the challenge is not knowing all the units — it is converting between them in a workflow where design tools, code, and component systems all speak different languages. A Figma file delivers specs in `px`. The company design system defines the typographic scale in `rem`. The layout uses breakpoints in `em` for maximum compatibility with older browsers. And the new hero component needs to occupy exactly the visible window height on mobile without being affected by the address bar. Having a converter with immediate visual context eliminates the need to open the browser console and do manual arithmetic at every layout decision.

Two points highlighted by WCAG — the web accessibility guidelines — deserve special attention. First: avoid `px` for font sizes, because `px` is the only unit that does not respect the text size preference the user has configured in their browser or operating system. Second: `100vw` includes the width of the vertical scrollbar when it is visible, which can cause horizontal overflow on pages where content is sized exactly to the viewport width — a subtle bug that only appears when content is long enough for the scrollbar to show up. And for mobile, using `100dvh` instead of `100vh` is the modern way to guarantee the layout occupies exactly the visible area regardless of the browser UI behavior.

Technical deep dive

Common questions summarized

  • What is this tool for?: It runs fully in your browser: useful to validate, format, or convert data in everyday development.
  • Are my inputs sent to a server?: Processing happens locally with JavaScript. We do not store what you paste into the text areas.
  • Can I use this for real production data?: Use at your own risk. For secrets (passwords, tokens), prefer controlled environments and your company policies. And always review the generated contents. Never trust blindly things you see on the internet.

Sample payload to try

  • See also the larger "Code Snippets" sample; paste this excerpt to try locally: Quick sample — Base 16px: 24px = 1.5rem = 1.5em Viewport 900px: 10vh = 90px

Tool guide

  • Absolute vs relative CSS units Absolute units (such as px) map to fixed CSS pixels. Relative units (rem, em, vh, vw, %, ch, ex, vmin, vmax, svh, lvh, dvh) depend on a context: root font size, local font size, viewport, or container.

  • PX, REM, and EM in practice px is straightforward for borders, shadows, and fine adjustments. rem scales from the root (html) font size and is excellent for global typography/spacing consistency. em scales from local context and works well when a component should scale with its own text.

  • VH and viewport units vh is a percentage of viewport height (100vh fills the visible height). On mobile, browser UI can change usable space, so svh, lvh, and dvh exist for dynamic viewport behavior. vw is the equivalent for width.

  • Other useful units % depends on property/reference context, ch approximates the width of the “0” glyph, fr distributes free space in CSS Grid, and cm/mm/in/pt/pc are mostly print-oriented.

  • What the tool does Converts between px, rem, em, and vh with configurable root size and viewport context. It also provides live visual previews for desktop and mobile so you can see scale changes instantly.

  • Why use it Speeds up design-system decisions, CSS refactors, and technical documentation by making unit trade-offs visible and testable in one place.

Code Snippets

Code example
Base 16px: 24px = 1.5rem = 1.5em
Viewport 900px: 10vh = 90px

Quick sample

Base 16px: 24px = 1.5rem = 1.5em
Viewport 900px: 10vh = 90px

FAQ

What is this tool for?

It runs fully in your browser: useful to validate, format, or convert data in everyday development.

Are my inputs sent to a server?

Processing happens locally with JavaScript. We do not store what you paste into the text areas.

Can I use this for real production data?

Use at your own risk. For secrets (passwords, tokens), prefer controlled environments and your company policies. And always review the generated contents. Never trust blindly things you see on the internet.