PX / REM / EM converter

Set root font-size in px and convert between px, rem, and em.

Overview

For years, pixels were the only unit that mattered in web design. When the standard screen was a 1024x768 CRT monitor, writing `font-size: 16px` meant something concrete and predictable. The iPhone in 2007 started to change that, and Apple's Retina display in 2010 completed the transformation: now there were more physical pixels than CSS pixels in the same area. The CSS pixel stopped being a physical dot on the screen and became an abstract unit — what the spec calls the reference pixel — calibrated to appear reasonably consistent across devices with different densities. Variable screen sizes, accessibility zooms, and system-level font size preferences emerged, and suddenly `px` alone was no longer sufficient to build interfaces that worked well for everyone.

The `em` unit has existed since CSS1 in 1996, but it has a behavior that catches many developers off guard: it is relative to the `font-size` of the parent element, not the document root. This means that inside a nested component, `1.2em` applied at three levels compounds to `1.2 × 1.2 × 1.2 = 1.728em` relative to the base size — a phenomenon called compound cascading that can cause typography to grow unexpectedly. The `rem` unit, introduced in CSS3 and safely supported since 2013, solves this by always being relative to the `font-size` of the `html` element. The classic trick of setting `font-size: 62.5%` on `html` comes from this: since the default size in most browsers is 16px, 62.5% of that is 10px, making `1rem` equivalent to `10px` and mental math much simpler.

The accessibility argument is where the choice between `rem` and `px` really matters. When a user goes into their operating system or browser settings and increases the default font size — common for people with low vision — layouts built with `px` completely ignore that preference. Layouts using `rem` adapt automatically. The `em` unit, on the other hand, shines when you want a component to be entirely self-contained: buttons, alerts, and cards that define internal spacing in `em` will scale proportionally if you simply change the `font-size` of the parent component, without having to adjust each property individually. The most widely adopted practical rule: use `rem` for typography and global spacing, `em` for isolated components that need to scale internally.

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: 16px base — 16px = 1rem = 1em (com contexto raiz) 24px = 1.5rem

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
16px = 1rem = 1em (com contexto raiz)
24px = 1.5rem

16px base

16px = 1rem = 1em (com contexto raiz)
24px = 1.5rem

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.