CSS Unit Converter
Convert between CSS units px, rem, em, and vw instantly. Set custom root font size and viewport width. Free, runs in your browser.
- Runs in your browser
- Your data never leaves your browser
- Free · No Sign-Up
Scan with WeChat to share this tool
Examples, details and FAQ Worked examples, how it compares with other tools, and answers to common questions.
Common Conversions
With the default settings (root font size 16px, viewport 1920px):
16px=1rem=1em=0.833333vw1rem=16px100vw=1920px=120rem
When to Use Each Unit
- px — a CSS pixel, not a device pixel: on a 2× screen one CSS pixel covers four device pixels, and page zoom enlarges it. It does not follow the browser’s font size setting. Good for borders, shadows, and fine details.
- rem — scales with the user’s browser font size setting, as long as the root font size is not fixed in px. Preferred for font sizes and spacing in accessible designs.
- em — relative to the element’s own font size (for
font-sizeitself, the parent’s). Useful for component-scoped sizing. - vw — relative to viewport width. Good for fluid typography and full-bleed layouts.
The Formulas
With a root font size of 16px and a 1920px viewport (the defaults):
rem = px ÷ root font size 24px ÷ 16 = 1.5rem
px = rem × root font size 1.5rem × 16 = 24px
vw = px ÷ viewport width × 100 24px ÷ 1920 × 100 = 1.25vw
px = vw × viewport width ÷ 100 1.25vw × 1920 ÷ 100 = 24px
Two More Examples
Phone layout. Set Viewport Width to 390 and convert 16px: the results are 1rem, 1em and 4.10256vw. Going the other way, 5vw on that viewport is 19.5px (1.21875rem). The same 5vw on the default 1920px viewport is 96px, which is why a pure vw font size is too small on phones and too large on desktops; the CSS clamp calculator builds a value with a floor and a ceiling instead.
A 10px root. Some projects set html { font-size: 62.5%; } so that 1rem is 10px with the default browser setting. Enter 10 as Root Font Size and 24px becomes 2.4rem. The 62.5% form keeps the user’s font setting in play: a reader who chose 20px in the browser gets a 12.5px root and the same 2.4rem renders at 30px. Writing html { font-size: 10px; } instead fixes the root, so rem values no longer follow that setting.
Why em Can Surprise You
The converter treats em like rem, both relative to the root font size. In a real page, em in font-size is relative to the parent’s font size, so nested em values multiply (MDN):
html { font-size: 16px; }
.card { font-size: 1.25em; } /* 20px */
.card .title { font-size: 1.25em; } /* 25px: 1.25 × 20px */
.card .title small { font-size: 1.25em; } /* 31.25px */
With rem instead, every level stays at 20px. Use em for things that should scale with their own text, such as padding inside a button, and rem for font sizes and layout spacing.
Limits
- em is converted as rem. The result is right only when the element’s font size equals the root font size.
- Four units only: px, rem, em, and vw.
vh,%,pt, andchare not converted. - vw uses the width you enter. The default 1920px is a desktop width; enter your target width (for example 390 for a phone) to get useful vw values.
- Results are rounded to 6 significant digits, for example
0.833333vwfor 16px at 1920px. - vw counts the scrollbar. In desktop browsers with a classic scrollbar,
100vwis the window width including the vertical scrollbar, so100vwcan be wider than the page’s content area and cause a horizontal scrollbar. - Only numbers are accepted in the Value field; typing
16pxwith the unit is not parsed. Choose the unit from the list instead. An empty or zero Root Font Size or Viewport Width uses 16px or 1920px; a negative one shows an error and clears the results.
FAQ
What CSS units does this tool support?
px, rem, em, and vw. Enter a value in any unit and see all four results at once.
What is rem and how is it calculated?
rem (root em) is relative to the root element's font size. By default that is 16px, so 1rem = 16px. You can change the root font size in the configuration.
How is vw calculated?
vw is 1% of the viewport width. With a viewport of 1920px, 1vw = 19.2px. Adjust the viewport width field to match your target layout.
What is the difference between rem and em?
rem is always relative to the document root font size. em is relative to the current element's font size, which varies in nested structures. This tool uses a simplified model where em = rem (both relative to root font size).
Is my data sent to a server?
No. The conversion runs in your browser tab, and the numbers you enter are not sent to a server or saved in browser storage. The page analytics records only usage events (the tool name and the action: convert or copy), not the values.