CSS Unit Converter

CSS Unit Converter

Convert between px, rem, em, vw, vh, %, pt, cm, mm, in instantly. Free tool for web developers.

Convert CSS Units

px
px
px

Common Presets

Font Sizes

10px 12px 14px 16px 18px 20px 24px 32px 48px 64px 1rem 1.25rem 1.5rem 2rem

Spacing

4px 8px 12px 16px 24px 32px 48px 64px 0.25rem 0.5rem 0.75rem 1rem

Breakpoints

320px (Mobile S) 375px (Mobile M) 768px (Tablet) 1024px (Laptop) 1280px (Desktop) 1440px (Large) 1920px (Full HD)

CSS Unit Quick Reference

UnitNameRelative ToExample
pxPixelsScreen (absolute)font-size: 16px
remRoot EMRoot font-size (:root/html)padding: 1.5rem
emEMParent element font-sizemargin: 2em
vwViewport Width1% of viewport widthwidth: 50vw
vhViewport Height1% of viewport heightheight: 100vh
%PercentageParent elementwidth: 50%
ptPoints1/72 of an inchfont-size: 12pt
cmCentimetersAbsolute (physical)width: 10cm
mmMillimetersAbsolute (physical)border: 1mm
inInchesAbsolute (physical)margin: 0.5in

What Are CSS Units?

CSS units define the size of elements on a web page. They fall into two categories: absolute units (like px, pt, cm) that have fixed sizes, and relative units (like rem, em, vw, vh, %) that scale based on other factors like font size or viewport dimensions.

Understanding CSS units is essential for building responsive, accessible websites. Choosing the right unit for each property affects how your layout adapts to different screen sizes and user preferences.

Absolute vs. Relative Units

Absolute units map to physical measurements. A pixel (px) is the most common absolute unit on screen. Points (pt), centimeters (cm), millimeters (mm), and inches (in) are primarily used for print stylesheets.

Relative units scale in proportion to something else. This makes them ideal for responsive design:

When to Use px vs rem vs em

Use rem for:

Use em for:

Use px for:

/* Recommended approach */
html { font-size: 100%; } /* 16px default */
body { font-size: 1rem; line-height: 1.6; }
h1 { font-size: 2.5rem; } /* 40px */
h2 { font-size: 2rem; } /* 32px */
.container { max-width: 60rem; } /* 960px */
.card { padding: 1.5rem; border: 1px solid #ccc; }

Responsive Design Best Practices with CSS Units

Choosing the right CSS unit is crucial for responsive layouts. Here are proven strategies used by professional web developers:

1. Use rem as Your Base Unit

Set your root font size to 100% (not a fixed px value) and use rem throughout. This ensures your entire layout respects the user's preferred font size and scales consistently.

2. Viewport Units for Full-Screen Layouts

Use vw and vh for hero sections, full-screen modals, and viewport-dependent sizing. Combine with min() and max() to prevent extreme sizes:

.hero { height: 100vh; }
.title { font-size: clamp(1.5rem, 4vw, 3rem); }
.sidebar { width: min(300px, 30vw); }

3. Use clamp() for Fluid Typography

The clamp() function combines min, preferred, and max values. It's perfect for font sizes that should scale with the viewport but within reasonable bounds.

h1 { font-size: clamp(1.75rem, 2vw + 1rem, 3rem); }
p { font-size: clamp(1rem, 1vw + 0.5rem, 1.25rem); }

4. Avoid Mixing Units Unnecessarily

Pick a primary unit system and stick with it. Mixing px, rem, and em inconsistently makes maintenance harder. A common approach is rem for sizing and spacing, px for borders and shadows.

CSS Unit Cheat Sheet

1rem = ?px

16px (default). Changes if you set a different font-size on the html element.

1em = ?px

Depends on parent. If parent is 16px, then 1em = 16px. Nesting compounds the value.

1vw = ?px

1% of viewport width. At 1920px width: 1vw = 19.2px.

1vh = ?px

1% of viewport height. At 1080px height: 1vh = 10.8px.

1pt = ?px

1.333px (at 96 DPI). Points are commonly used in print CSS.

1in = ?px

96px (at standard screen DPI). 1 inch = 2.54cm = 25.4mm.

1cm = ?px

37.795px (at 96 DPI). Rarely used on screen, common in print.

100% = ?

Depends on property. For width: parent's width. For font-size: parent's font-size.

Frequently Asked Questions

How do I convert px to rem?

To convert px to rem, divide the pixel value by the root font size (usually 16px). For example, 24px / 16 = 1.5rem. Use our converter above for instant results with any base font size.

What is the difference between rem and em in CSS?

rem is relative to the root element's font size (html element, usually 16px). em is relative to the parent element's font size. rem is more predictable because it always refers to the root, while em can compound when nested. For example, a 2em inside another 2em element would result in 4x the root font size.

What does 1vw equal in pixels?

1vw equals 1% of the viewport width. On a 1920px wide screen, 1vw = 19.2px. On a 1440px screen, 1vw = 14.4px. The pixel value changes based on the user's screen size.

Should I use px or rem for font sizes?

Use rem for font sizes in most cases. rem respects user browser settings for accessibility, scales proportionally, and makes responsive design easier. Use px only when you need exact pixel-perfect sizing that should never change.

How do I convert px to vw for responsive design?

To convert px to vw, use the formula: vw = (px / viewport width) x 100. For example, on a 1440px design: 720px / 1440 x 100 = 50vw. Our converter lets you set any viewport width for accurate results.

What is the default browser font size?

The default browser font size is 16px in all major browsers (Chrome, Firefox, Safari, Edge). This means 1rem = 16px by default. Users can change this in their browser settings for accessibility.