CSS Unit Converter
From
px
px
px
Converted To
px 16px
rem 1rem
em 1em
vw 0.833vw
pt 12pt
cm 0.423cm

Real-time CSS unit converter • Supports px, rem, em, vw, pt, cm, in, mm • Auto-updates on input

CSS Unit Converter

CSS Units: The Complete Guide

CSS units define how big or small something is - from font sizes to margins, widths, and animations. Choosing the right unit is crucial for responsive, accessible, and maintainable designs.

Two Main Categories of CSS Units

Category Description Scalable?
Absolute (Fixed) Fixed physical size — doesn’t change with screen or settings. No
Relative Relative to something else (parent, viewport, font, etc.). Yes

1. Absolute Units

Best for print or when you need exact physical sizes.

UnitNameSizeUse Case
cmCentimeters1 cm = 37.8px (96 DPI)Print layouts
mmMillimeters1 mm = 0.1 cmPrint
QQuarter-millimeters1 Q = 0.25 mmHigh-precision print
inInches1 in = 2.54 cmPrint (US)
pcPicas1 pc = 12 ptTypography (print)
ptPoints1 pt = 1/72 inPrint fonts
pxPixels1 px = 1/96th of 1 in (CSS spec)Screens (most common)
.print-label {
  font-size: 12pt;     /* Print */
  margin: 1cm;         /* Print */
}
.screen-icon {
  width: 32px;         /* Screen */
}

px is not truly "absolute" on screens - it’s reference pixel, scaled by device DPI.

2. Relative Units

Scale with context - perfect for responsive design and accessibility.

Font-Relative Units

UnitRelative ToExample
emFont size of the element (for itself) or parent (for children)font-size: 1.5em; → 1.5 × parent font
remFont size of the root element (<html>)font-size: 1.2rem; → 1.2 × root font (usually 16px)
lhLine height of the elementmargin-top: 2lh; → 2 × line height
rlhLine height of the rootpadding: 1rlh;
capCap height of the fontfont-size: 3cap;
chWidth of the "0" characterwidth: 40ch; → ~40 characters wide
exHeight of the lowercase "x"line-height: 3ex;
icWidth of the CJK water ideograph (东)width: 10ic;
html { font-size: 16px; } /* Root */
.title { font-size: 2rem; }   /* 32px */
.card { padding: 1.5em; }     /* 1.5 × card's font-size */
p { margin-bottom: 1.2em; }

Viewport-Relative Units

Relative to the viewport (browser window).

UnitRelative ToExample
vw1% of viewport widthfont-size: 5vw; → 5% of screen width
vh1% of viewport heightheight: 100vh; → full screen height
vmin1% of smaller dimension (width or height)Square on any screen
vmax1% of larger dimensionFill largest side
svw/svhSmall viewport (excludes UI bars)Mobile safe areas
lvw/lvhLarge viewport (includes scrollbars)Desktop
dvw/dvhDynamic — updates on resize/zoomModern layouts
.hero {
  height: 100vh;           /* Full height */
  font-size: clamp(1rem, 5vw, 3rem);
}
.square {
  width: 50vmin;
  height: 50vmin;          /* Always square */
}

Container-Relative Units (New!)

Introduced in CSS Containment Module - relative to parent container size.

UnitRelative ToRequires
cqw1% of container widthcontainer-type: inline-size;
cqh1% of container heightcontainer-type: size;
cqi1% of container inline size (width in LTR)Modern responsive components
cqb1% of container block size (height in LTR)Grid/flex children
cqmin, cqmaxSmaller/larger of cqi/cqbAdvanced
.card {
  container-type: inline-size;
}
.card-title {
  font-size: 5cqw;   /* Scales with card width */
}

Percentage (%)

Relative to parent element’s corresponding dimension.

.box {
  width: 50%;      /* 50% of parent width */
  padding-top: 75%; /* Square using padding trick */
}

Special Units

UnitPurpose
frCSS Grid — fractional unit for remaining space
0Zero — no unit needed: margin: 0;
autoLet browser decide (not a unit, but keyword)
calc()Mix units: width: calc(100% - 2rem);
clamp()Responsive: font-size: clamp(1rem, 4vw, 2rem);
min(), max()Choose smallest/largest value
.grid {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
}
.responsive {
  font-size: clamp(1rem, 2.5vw + 0.5rem, 3rem);
}

Best Practices

Quick Reference Table

UnitTypeScales WithBest For
pxAbsoluteIcons, borders
remRelativeRoot fontTypography, spacing
emRelativeParent fontComponent padding
%RelativeParent sizeWidths, layouts
vwViewportScreen widthLarge text, heroes
chFontCharacter widthLine length (50–75ch)
frGridAvailable spaceGrid columns
cqwContainerParent containerModern components


Master CSS units → build layouts that work everywhere.

Last update: 02. 11. 2025.