Skip to content

CSS Units Converter

Convert CSS lengths between px, rem, em, percent, vw and vh in your browser. Set root and parent font-size, viewport and basis for accurate results.

Runs entirely in your browser. Nothing you paste here is sent to us or anyone else โ€” there is no server processing, no logging of input, and no third-party scripts on this page.

A CSS units converter turns a length written in one unit into its equivalent in px, rem, em, percent, vw and vh โ€” using the root font-size, parent font-size, viewport size and percentage basis you supply, because relative units only have a pixel value in context. Type a value on the left, pick its unit, and the equivalents appear on the right. It all runs in your browser; nothing you enter is sent anywhere.

What are CSS length units?

CSS measures lengths with two families of units. Absolute units โ€” chiefly px โ€” map to a fixed number of device pixels. Relative units resolve against something else at the moment they are used, which is what makes them flexible and also what makes a naive converter wrong. The units this tool handles are:

Unit Relative to Example
px nothing โ€” absolute pixels 24px is always 24px
rem root (html) font-size 1.5rem = 24px when root is 16px
em the element or parent font-size 2em = 32px when parent is 16px
% a property-specific basis 50% width = half the container
vw 1% of viewport width 10vw = 192px on a 1920px screen
vh 1% of viewport height 10vh = 108px on a 1080px screen

Why the extra input fields exist

Converting px to and from rem is straightforward once you know the root font-size, which defaults to 16px in every major browser. But em, %, vw and vh have no single correct pixel value โ€” they depend on the surroundings. An em follows the parent element’s font-size. A percentage means different things for width, font-size and line-height, so you have to tell the tool what the percentage is measured against. And vw/vh change with the viewport, which differs on every device. Rather than pretend those units convert cleanly on their own, this converter asks you for the context so the result is honest and exact. The viewport fields are pre-filled with your current window size as a convenience.

A worked example

Suppose your design system uses a 16px root font-size and you want a heading set to 2rem. Enter 2 and rem: the tool anchors it to 32px, then reports 2em (against a 16px parent), 200% (against a 16px basis), and roughly 1.667vw on a 1920px-wide screen. Change the root font-size to 20px and the same 2rem now resolves to 40px, and every other equivalent updates with it. That instant recalculation is the point: you can see how one length behaves under different contexts without redoing the maths.

When to use each unit

  • rem โ€” font sizes and spacing that should respect the user’s browser font-size preference. Predictable across the whole page.
  • em โ€” spacing inside a component that should scale with its own text, such as button padding tied to its label size.
  • % โ€” fluid widths and heights that track their container.
  • vw / vh โ€” full-bleed sections, fluid type, and elements sized to the screen. Watch out for vh quirks with mobile browser toolbars.
  • px โ€” hairline borders and other details that must not scale.

Accuracy and privacy

The conversion is ordinary arithmetic โ€” everything is normalised to pixels and back โ€” so there is no rounding beyond a six-decimal display tidy-up that never affects rendering. Because it is just maths, the whole tool runs locally in your browser: there is no upload, no logging, and no third-party analytics on this page. Load it once and it keeps working offline.

Frequently asked questions

How do px and rem relate?

One rem equals the root font-size, which browsers default to 16px. So 1rem is 16px, 1.5rem is 24px, and 24px is 1.5rem. Change the root font-size field if your site sets a different value on the html element.

Why do em, percent and vw need extra inputs?

Because they are relative units with no fixed pixel value on their own. An em depends on the parent element's font-size, a percentage depends on whatever property it applies to, and vw/vh depend on the viewport size. Those inputs supply the context so the conversion can be exact rather than a guess.

What is the difference between rem and em?

Both are relative to a font-size, but rem always uses the root (html) font-size while em uses the font-size of the current element's parent. That makes rem predictable across a page and em useful for components that should scale with their local text size.

What percentage basis should I use?

It depends on the property. For font-size, percentages resolve against the parent font-size. For width, they resolve against the containing block's width. For line-height, against the element's own font-size. Enter whichever pixel value the percentage should be measured against.

Is 1vw always the same number of pixels?

No. 1vw is one percent of the viewport width, so it changes with the browser window and device. The tool fills the viewport fields with your current window size, but you can type any width and height to preview another screen.

Should I use px or rem for font sizes?

Many teams prefer rem for font sizes and spacing because it respects the user's browser font-size setting, which helps accessibility. Pixels are fine for borders and fixed hairlines. This converter lets you move between them without doing the arithmetic by hand.

Does the converter round my values?

Results are rounded to six decimal places and trailing zeros are dropped, so 16px shows as 1rem rather than 1.000000. That precision is far finer than any browser renders, so it will not affect layout.

Is anything I type sent to a server?

No. The conversion is plain arithmetic that runs entirely in your browser. Nothing is uploaded, logged, or stored, and the tool keeps working if you go offline after the page loads.