CSS length bench
px to rem.
Convert pixels as you type. Rewrite a stylesheet. Draw a fluid clamp() between two viewport widths. The root starts at 16px, the usual browser default for medium.
16px is 1rem
01Convert
Edit any unit. The others follow. rem uses the root. em, font-size %, and the ch fallback use the em context.
1ch = 8px · CSS fallback, 0.5 × 16px.
pt is exact: 1pt = 1/72in = 4/3px. vw and vh are 1% of the width and height above, not this browser, unless you use the window button. A root of 10px is what html { font-size: 62.5% } computes to when the initial size is 16px.
02Common values
1–96px. Click a value to copy it. Arrow keys move inside the table, Enter copies.
| px | rem | em | pt | ch ≈ |
|---|
03Rewrite a snippet
Every px length becomes rem. Comments, strings, and urls are left alone. @media and @import breakpoints use the media basis, because those rem values follow the browser’s initial font size, not your root. Rules inside the query still use the root. A 1px border or outline can stay in px so the hairline does not round away. Radius, shadow, and spacing still convert.
04Fluid type
A straight line from the size at the narrow viewport to the size at the wide one, written as rem plus vw, then clamped. Outside that span the nearer size holds. The preview is the real CSS pixel size for the width you choose — the slider simulates a viewport, it does not scale a mockup.
34px · 2.125rem at 820px wide. Scaling between the two sizes.
05How the units work
- px
- A CSS pixel is 1/96 of an inch. On a screen that inch is a reference, not a ruler.
1in = 96px. - rem
- The root element’s computed font size. On the root’s own
font-size, and in media queries,remuses the initial size instead (usually 16px). A root of 10px is the 62.5% trick:html { font-size: 62.5% }when the initial size is 16px. - em
- On
font-size,emis the parent’s computed font size. On other properties it is the element’s own font size. The em context is whichever of those you are converting against. - %
- Font-size percentages refer to the parent’s computed font size, same anchor as
emonfont-size. Negative percentages are invalid there. A percentage on width or margin is a different reference; this field is only the font-size kind.100%equals1em. - pt
- One point is 1/72 inch. Because one inch is 96px,
1pt = 4/3pxand1px = 0.75pt. On a monitor this is not a physical printer’s point. - vw and vh
1vwis 1% of the viewport width you supply,1vhis 1% of the height. Unprefixedvwandvhfollow the large viewport. They ignore overlay scrollbars unless the root forces a scrollbar. “Use this window” copiesinnerWidthandinnerHeight, which can differ by that scrollbar.- ch
- The advance of the glyph “0” (U+0030) in the element’s font. If that width cannot be measured, CSS says to assume
0.5emwide (or1emwhen the zero is typeset upright). The fallback is exact as a rule and only approximate as a character width. Measuring a font here is also approximate: hinting can disagree with layout by a fraction of a pixel. - clamp()
clamp(MIN, VAL, MAX)ismax(MIN, min(VAL, MAX)). If MIN is greater than MAX, the result sticks at MIN, so this tool orders the bounds smaller to larger. The middle term is the line between your two breakpoints: intercept in rem, plus the slope times100vw. Bounds in rem follow the root when the user changes their font size. Thevwterm follows the viewport and does not.
- CSS Values and Units Level 4 · Absolute lengths (opens in a new tab)
- CSS Values and Units Level 4 · Font-relative lengths (opens in a new tab)
- CSS Values and Units Level 4 · Viewport-percentage lengths (opens in a new tab)
- CSS Values and Units Level 4 · clamp() (opens in a new tab)
- CSS Fonts Level 4 · font-size (opens in a new tab)
Line-height in px is converted to rem, which stays tied to the root. A unitless line-height is a multiplier of the element’s own font size; this tool does not invent one. Hairline borders are the reason the snippet can keep 1px: at a 16px root that length is 0.0625rem, and used border widths round to device pixels.