How to use CSS Unit Converter
- Enter a nonnegative value without a unit, then choose Convert from and Convert to. The same unit on both sides keeps the value in that unit.
- Enter the bases needed for the conversion: root font size for rem, the applicable font-size basis for em, reference size for %, or viewport width/height for vw/vh. The page does not read another site.
- Optionally add one length per line to Convert a list of lengths. A line such as 24px carries its own source unit; a bare number uses Convert from. All lines use Convert to.
- Enable Add a px to rem table if you need common sizes from 8px to 64px at your entered root size. Read the conversion path and bases before copying the result.
Example: CSS Unit Converter
Convert 2rem to CSS pixels using an entered root font size of 16px.
Options
- Value and units
- Value accepts 0 to 100000. Choose px, rem, em, %, vw, vh or pt; enter the number without a unit in the single-value field.
- Root and em font sizes
- The Root font size field defaults to 16px, but your page or browser preferences can use another size. For em, use the inherited font size when converting font-size itself, and the element’s own computed font size for properties such as padding. Enter that basis in the Font size for em field.
- Reference and viewport sizes
- One percent is the supplied reference size divided by 100. The correct reference depends on the CSS property. One vw uses viewport width divided by 100, and one vh uses viewport height divided by 100. Enter these dimensions in CSS pixels.
- Points
- The converter uses 1pt = 4/3 CSS pixels. That relationship does not mean a screen measurement will match a physical ruler.
- List and quick table
- The list accepts up to 50 nonempty lines, with a number and optional unit on each. The first invalid line stops the run with its line number. The separate quick table shows 13 px-to-rem conversions using the entered root size.
Supported inputs and limits
- Supports px, rem, em, %, vw, vh and pt.
- Values accept 0 to 100000; font-size bases accept 1px to 1000px; reference and viewport sizes accept 1px to 100000px.
- The page uses the sizes you enter and does not infer property context, nested font sizing or mobile browser interface changes.
- Dynamic/small viewport units and whole stylesheet conversion are unsupported.
- Fractional results round half up to six decimal places, except that a positive value that would round to zero keeps its digits.
More details
The optional list accepts up to 50 nonempty lines and stops at the first invalid line.
It does not return a partially successful list.
Inputs for unused size references still need to be empty or valid.
Where your input is processed
This tool does not upload your inputs. See the limits for anything saved on your device.
Choose the basis for the property you are measuring
A button can inherit a 16px font and set its own font-size to 1.25em, making that font 20px. Padding of 1em on the button then uses 20px, not the parent’s 16px. Enter 16 as the em basis for the font-size calculation and 20 for the padding calculation. Check computed styles in the browser when the basis is unclear.
Rounding inside a compiled stylesheet
A division such as 20px into rem at a 16px root gives 1.25rem, which finishes exactly. Other pairs do not finish, and the converter rounds the printed answer to six decimal places while the arithmetic keeps more digits. When a design system stores rem values, round the final figure once instead of rounding at every step of a chain.
Questions about CSS Unit Converter
What is the difference between rem and em?
A rem usually uses the root element’s font size. An em uses the element’s computed font size for properties such as padding, but uses its inherited font size when setting font-size itself. Enter the appropriate basis for the property you are converting.
Why does the formula line show a font size?
Relative units need a size to become pixels. The formula names the entered root, em, percentage or viewport basis so you can check the assumption. A pt conversion uses the fixed 4/3 CSS-pixel relationship.
What if my page sets a smaller root font size?
Type that size in Root font size and the rem answers follow it. A root set to 10px, for example, makes 2rem equal 20px on that page.
Does the tool read my stylesheet?
No. It works only with the numbers on the page, inside your browser. None of your site files or settings are uploaded.
What size should I enter for percent or viewport units?
For %, enter the size that the CSS property uses as its reference. For vw and vh, enter the viewport width and height in CSS pixels. These are your inputs; the page does not measure another site or guess the element context.