ToolDeck

CSS Unit Converter

Convert CSS units between px, rem, em, vw, vh and %

px16
rem1
em1
vw1.111111
vh1.777778
%100
pt12
cm0.4233331
mm4.233331
in0.1666667

What is CSS Unit Conversion?

A CSS unit converter is a tool that translates length values between different CSS measurement systems. CSS defines over a dozen length units, split into two groups: absolute units like px, pt, cm, and in that map to fixed physical measurements, and relative units like rem, em, vw, vh, and % that depend on context such as font size or viewport dimensions.

Browsers resolve all CSS lengths to pixels during rendering. When you write 1.5rem, the browser multiplies 1.5 by the root font-size (typically 16px) to get 24px. When you write 50vw, it takes half the current viewport width. Understanding these relationships is necessary for building layouts that scale across devices and respect user preferences like custom font sizes set in the browser.

The CSS Values and Units Module Level 4 specification (W3C) defines the exact conversion ratios between all absolute units: 1in = 96px = 72pt = 2.54cm = 25.4mm. Relative units have no fixed ratio because they depend on runtime context. A free CSS unit converter lets you calculate these relationships instantly given your specific root font-size and viewport dimensions, without writing any code.

Why Use a CSS Unit Converter?

Converting between CSS units by hand means remembering ratios, pulling up a calculator, and double-checking your math. This tool does the conversion in your browser with zero friction.

Convert instantly
Enter a value, pick the source unit, and see results in all 10 CSS units at once. No need to run separate calculations for px-to-rem, px-to-vw, or px-to-pt.
🔒
Keep your data private
All conversions run locally in your browser. No values are sent to a server, logged, or stored. Close the tab and the data is gone.
🎯
Match your exact context
Set your root font-size, viewport width, viewport height, and parent font-size. The converter uses these values to produce accurate results for rem, em, vw, vh, and % units.
📏
Cover all CSS length units
Supports px, rem, em, vw, vh, %, pt, cm, mm, and in. Whether you are working with screen layouts, print stylesheets, or responsive typography, every unit is covered.

CSS Unit Converter Use Cases

Frontend Development
Convert a design file's pixel values to rem for a component library. When a Figma mockup specifies 24px spacing, convert it to 1.5rem so the layout scales with the user's font-size preference.
Backend / Full-Stack Engineering
Generate PDF or email templates where dimensions are specified in pt or cm. Convert your CSS pixel values to print-ready point sizes for server-side rendering with tools like Puppeteer or wkhtmltopdf.
DevOps / CI Pipelines
Validate that a design system's spacing tokens use consistent units across build steps. Quickly verify that a 16px base produces the expected rem values in generated CSS.
QA / Visual Testing
Verify computed styles during cross-browser testing. When Chrome DevTools shows a computed value of 14.4px, convert it to rem to confirm it matches the expected 0.9rem from the stylesheet.
Data Visualization
Size SVG or canvas elements relative to viewport dimensions. Convert fixed pixel chart widths to vw units so visualizations fill a consistent percentage of the screen on different monitors.
Learning CSS
Understand the relationship between rem, em, and px by experimenting with different base sizes. Change the root font-size from 16px to 18px and see how every rem value shifts.

CSS Length Units Reference

CSS defines 10 commonly used length units. Absolute units have a fixed conversion to pixels. Relative units depend on context: the root font-size for rem, the parent font-size for em, and the browser viewport for vw and vh.

UnitNameDefault sizeRelative to
pxPixel1pxFixed; 1px = 1/96 of 1in on screens
remRoot em16px (default)Relative to <html> font-size
emEmInheritedRelative to parent element font-size
vwViewport width1% of viewportRelative to browser window width
vhViewport height1% of viewportRelative to browser window height
%PercentageVariesRelative to parent property value
ptPoint1.333pxPrint unit; 1pt = 1/72 of 1in
cmCentimeter37.795pxPhysical unit; 1cm = 96px / 2.54
mmMillimeter3.7795pxPhysical unit; 1mm = 1cm / 10
inInch96pxPhysical unit; 1in = 96px (CSS spec)

Absolute vs Relative CSS Units

Choosing between absolute and relative units affects how your layout responds to different screens and user settings. Each group has distinct trade-offs.

Absolute Units (px, pt, cm, mm, in)
Absolute units produce the same physical size regardless of context. Use px for borders, shadows, and elements that should not scale. Use pt for print stylesheets. The CSS spec defines 1in = 96px, though actual physical size varies by display DPI.
Relative Units (rem, em, vw, vh, %)
Relative units scale with their reference context. Use rem for font-sizes and spacing to respect user preferences. Use em for component-internal scaling (padding relative to the element's own font-size). Use vw/vh for viewport-filling layouts like hero sections.

Common px to rem Conversion Table

This table assumes a root font-size of 16px (the browser default). If your project uses a different base, divide the pixel value by your base to get the rem equivalent.

pxremptTypical use
100.6257.5Small caption text
120.759Body text (compact)
140.87510.5Default body text
16112Root font-size (browser default)
181.12513.5Large body text
201.2515H4 heading
241.518H3 heading
32224H2 heading
48336H1 heading
64448Display / hero text

Code Examples

These examples show how to convert CSS units programmatically in JavaScript, Python, CSS custom properties, and Sass.

JavaScript
// px to rem (given root font-size of 16px)
const pxToRem = (px, base = 16) => px / base
pxToRem(24)  // → 1.5

// rem to px
const remToPx = (rem, base = 16) => rem * base
remToPx(1.5) // → 24

// px to vw (given viewport width of 1440px)
const pxToVw = (px, viewport = 1440) => (px / viewport) * 100
pxToVw(360)  // → 25

// Dynamic calculation using getComputedStyle
const rootFontSize = parseFloat(
  getComputedStyle(document.documentElement).fontSize
) // → 16 on most browsers
Python
# CSS unit converter functions

def px_to_rem(px: float, base: float = 16) -> float:
    return px / base

def rem_to_px(rem: float, base: float = 16) -> float:
    return rem * base

def px_to_vw(px: float, viewport: float = 1440) -> float:
    return (px / viewport) * 100

def px_to_pt(px: float) -> float:
    return px * 72 / 96

print(px_to_rem(24))     # → 1.5
print(rem_to_px(2.5))    # → 40.0
print(px_to_vw(720))     # → 50.0
print(px_to_pt(16))      # → 12.0
CSS (calc & custom properties)
/* Define a base scale using rem */
:root {
  --base: 16px;       /* root font-size */
  --space-1: 0.25rem; /* 4px */
  --space-2: 0.5rem;  /* 8px */
  --space-4: 1rem;    /* 16px */
  --space-8: 2rem;    /* 32px */
}

/* Fluid typography: scales between 1rem (16px) and 2.5rem (40px) */
h1 {
  font-size: clamp(1rem, 2.5vw + 0.5rem, 2.5rem);
}

/* Viewport-relative hero height */
.hero {
  height: calc(100vh - 4rem); /* full viewport minus 64px header */
}

/* Percentage-based grid */
.sidebar { width: 25%; }     /* 360px on 1440px screen */
.content { width: 75%; }     /* 1080px on 1440px screen */
SCSS (mixin)
// Reusable px-to-rem function in Sass
@use "sass:math";

$base-font-size: 16px !default;

@function rem($px) {
  @return math.div($px, $base-font-size) * 1rem;
}

// Usage
.card {
  padding: rem(24px);       // → 1.5rem
  margin-bottom: rem(32px); // → 2rem
  border-radius: rem(8px);  // → 0.5rem
  font-size: rem(14px);     // → 0.875rem
}

Frequently Asked Questions

What is the default root font-size in browsers?
All major browsers (Chrome, Firefox, Safari, Edge) default to a root font-size of 16px. This means 1rem = 16px unless the user or a stylesheet overrides the html element's font-size. Some users increase this in browser settings for accessibility, which is why rem is the better default for text rather than px.
How do I convert px to rem?
Divide the pixel value by the root font-size. With the default 16px base: 24px / 16 = 1.5rem. If your project sets html { font-size: 10px } (a common reset), then 24px / 10 = 2.4rem. The formula is always: rem = px / root-font-size.
What is the difference between rem and em?
rem is relative to the root element's font-size (the html tag), while em is relative to the current element's parent font-size. This means rem produces consistent sizing across the entire page, while em compounds when nested. A 2em inside a 2em parent becomes 4x the root size. Use rem for global spacing and font sizes; use em when you want sizing to scale relative to the component's own text.
When should I use vw or vh units?
Use vw for elements that should scale with the browser window width, such as full-width hero sections or fluid typography (clamp with vw). Use vh for full-screen sections or viewport-height layouts. Be cautious with vh on mobile browsers where the address bar changes the viewport height; the newer dvh (dynamic viewport height) unit solves this.
Can I mix different CSS units in the same property?
Yes. The CSS calc() function lets you combine any units in a single expression. For example, width: calc(100vw - 2rem) subtracts 32px (at default base) from the full viewport width. You can also mix units in clamp(): font-size: clamp(1rem, 2vw + 0.5rem, 2.5rem) creates fluid typography that scales between 16px and 40px.
How many pixels is 1pt in CSS?
In CSS, 1pt = 1/72 of an inch, and 1 inch = 96px, so 1pt = 96/72 = 1.333px. This ratio is fixed in the CSS specification regardless of screen DPI. Points are primarily used in print stylesheets and PDF generation. For screen design, px or rem are better choices.
Is 62.5% font-size reset still a good practice?
Setting html { font-size: 62.5% } makes 1rem = 10px, which simplifies mental math (24px = 2.4rem). However, it requires you to explicitly set font-size on the body element and can cause issues with third-party components that assume the default 16px base. The modern preference is to keep the 16px default and use a Sass function or PostCSS plugin to handle the conversion instead.