Convert CSS units instantly
A CSS Unit Converter helps you switch between common CSS length units without doing manual math.
This tool can convert:
- px
- rem
- em
- vw
- vh
- vmin
- vmax
- pt
- %
You can use it in two ways:
- paste raw values like
16,24, or48 - paste full CSS like
margin: 16px 24px;orfont-size: 12pt;
That makes it useful for quick one-off conversions, design system cleanup, responsive refactors, and converting larger CSS snippets without editing each value by hand.
Why a CSS unit converter is useful
CSS units are not all based on the same reference.
Some are absolute or near-absolute:
pxpt
Others depend on context:
remdepends on the root font sizeemdepends on the element or chosen font context%depends on a reference valuevw,vh,vmin, andvmaxdepend on viewport size
That means converting units is not always as simple as moving a decimal point.
This tool gives you a fast way to apply the right assumptions and see the result instantly.
What this tool does
This CSS Unit Converter is built for practical front-end work.
You can:
- choose a From unit and a To unit
- set the Base Font used for rem, em, and percentage conversions
- set Viewport Width and Viewport Height for viewport-based units
- paste plain numbers for line-by-line conversion
- paste CSS declarations and convert matching values inline
- swap conversion direction instantly
- copy the converted CSS output in one click
The component is designed to parse each line intelligently:
- if a line is just a number, it treats that value as the selected source unit
- if a line contains CSS, it finds matching values in the source unit and replaces only those
That makes it flexible enough for both quick calculations and real stylesheet editing.
Supported unit conversions
Pixels (px)
Pixels are the most familiar CSS length unit and are commonly used for spacing, borders, and dimensions.
Root em (rem)
rem is based on the root font size, usually the html font size.
It is a popular choice for:
- scalable typography
- accessible spacing systems
- design tokens
- responsive layouts
Element em (em)
em is relative to a font-size context.
This tool uses the Base Font setting as the reference so you can test and convert values consistently.
Viewport Width (vw)
vw is based on the viewport width.
1vw equals 1% of the viewport width.
Viewport Height (vh)
vh is based on the viewport height.
1vh equals 1% of the viewport height.
Viewport Min (vmin)
vmin uses the smaller side of the viewport.
Viewport Max (vmax)
vmax uses the larger side of the viewport.
Points (pt)
pt is a print-oriented unit that still appears in some imported CSS, editor exports, and legacy styles.
Percentage (%)
Percentage-based conversions need a reference value. In this tool, % uses the Base Font setting as the reference context for conversion.
How to use the CSS Unit Converter
1. Set the conversion context
Before converting, choose the values that affect context-sensitive units.
Base Font (px)
This setting is used for:
remem%
A common default is 16px, but you can change it to match your project.
Examples:
16pxroot font size10pxroot font size for decimal-friendly systems18pxfor larger base typography
Viewport Width and Viewport Height
These settings are used for:
vwvhvminvmax
You can enter the screen size you want to simulate, such as:
1440 × 9001920 × 1080390 × 844
This helps when converting responsive values into fixed ones or testing how a viewport unit behaves on a target screen size.
2. Choose the source and target units
Select the unit you want to convert from and the unit you want to convert to.
Examples:
px → remrem → pxpx → emvw → pxvh → rempt → px
Use the swap button to reverse the direction instantly.
3. Paste values or CSS
The left-hand input box accepts both plain values and CSS snippets.
Plain values
You can paste one value per line:
16
24
32
48
If the selected source unit is px, the output becomes the converted result in the target unit.
CSS input
You can also paste CSS directly:
margin: 16px 24px;
font-size: 12pt;
width: 50vw;
min-height: 100vh;
The tool will find matching values in the selected source unit and replace them inline.
4. Copy the result
The converted output appears in the right-hand panel.
Use Copy CSS to copy the updated values or CSS in one click.
How the conversion logic works
The tool converts units in two steps.
Step 1: Normalize to px
Every input value is first converted into pixels.
Examples:
1rembecomesbase font size in px50vwbecomes half of the viewport width in px12ptbecomes pixels using the CSS point-to-pixel ratio
Step 2: Convert px into the target unit
Once the value is normalized to pixels, it is converted from px into the selected target unit.
This approach keeps the logic consistent across all supported pairs.
The output is then rounded for cleaner CSS, with trailing zero noise removed.
Common CSS unit conversions
px to rem
This is one of the most common front-end conversions.
It is useful when moving from fixed spacing or typography into a more scalable system.
Example with a 16px base font:
16px = 1rem24px = 1.5rem32px = 2rem
rem to px
Useful when you already have tokenized or responsive styles but need exact pixel values for specs, reviews, or legacy code.
px to em
Helpful when converting component styles into relative values tied to font size.
px to vw or vh
Useful when exploring viewport-based responsive layouts, especially for hero sections, fluid spacing, or height-driven layouts.
vw to px
Useful when you want to see what a responsive value becomes on a specific screen size.
pt to px
Handy when importing styles from print-oriented or editor-generated sources.
% to px
Useful when you want to interpret a percentage value against the chosen base context.
Real-world use cases
Convert a design system from px to rem
If you are moving toward scalable typography and spacing, this tool helps turn pixel-based values into rem values quickly.
Clean up copied CSS
Paste CSS from a design handoff, third-party snippet, or old stylesheet, then convert the values you want without editing each declaration manually.
Understand responsive values on real screen sizes
If a layout uses vw, vh, vmin, or vmax, you can simulate a viewport and see the actual pixel result immediately.
Standardize units across a project
Teams often want to normalize units so spacing, type, and layout values follow a consistent convention.
Prepare content for tutorials or docs
This is also useful when writing technical articles, demos, or examples that show both original and converted CSS values.
Important assumptions to understand
Not every CSS unit conversion is universal.
rem and em need a font-size context
Without a base font size, there is no single correct px ↔ rem or px ↔ em conversion.
This tool makes that context explicit through the Base Font setting.
Viewport units depend on screen size
vw, vh, vmin, and vmax all depend on viewport dimensions.
That means the same CSS value can convert to different pixel values on different screens.
Percentage values need a reference
A percentage only becomes a concrete length when you define what it is relative to.
In this tool, % uses the chosen base font context.
This makes the conversions predictable and useful for workflow consistency, but it is still important to remember the assumption behind the result.
Common mistakes and how to avoid them
Forgetting the base font setting
If your project uses 10px or 18px as a root size, leaving the tool at 16px will give you the wrong rem or em output for that system.
Treating viewport conversions as fixed everywhere
A vw value is not one static pixel value across all devices. Always choose viewport dimensions that match the screen you care about.
Mixing raw numbers and CSS expectations
Plain number lines are treated as values in the selected source unit. CSS lines are parsed and converted inline.
Assuming % is universal
Percentage conversions always depend on a reference. This tool uses the Base Font setting, so make sure that matches your intended context.
Why this tool is helpful
You can always do CSS unit math by hand or in code, but this tool speeds up the everyday parts of front-end work.
It is useful when you want to:
- convert several spacing values quickly
- transform a CSS snippet from one unit system to another
- test responsive values against a real viewport
- prepare cleaner values for a refactor
- compare px, rem, em, and viewport units side by side
- generate copy-ready CSS without repetitive editing
It turns a repetitive workflow into something fast and visual.
Perfect for
- front-end developers
- designers working with dev handoff values
- engineers refactoring design systems
- teams moving from px to rem
- developers debugging viewport-based layouts
- anyone who needs an online CSS Unit Converter
If you need to convert px, rem, em, vw, vh, vmin, vmax, pt, or percentage values quickly, this tool gives you a simple way to do it with the right context settings built in.
Paste values or full CSS, choose your units, adjust the base font and viewport, and copy the converted output instantly.