Home › Guides › Reference › CSS Units Reference

CSS Units Reference

CSS length units grouped by type: absolute, font-relative, viewport (svh, lvh, dvh), container query units and percentages.

By the tools4free.dev team · Last reviewed 4 December 2026

How to use this reference

Every size in CSS is a number plus a unit, such as 16px, 1.5rem or 50vw. The unit decides what the number is measured against. Some units are fixed, so 1in is always 96px. Others are relative, so 1em depends on a font size, 1vw depends on the browser window and 1cqw depends on a parent container. Picking the right unit is what makes a layout adapt to different screens, user font settings and component sizes.

The tables below group the units by what they are relative to: absolute units, font-relative units, viewport units, container query units and percentages. Each row gives the meaning and a note on when to use it. A short section at the end covers the units for angles, time and image resolution, which you need for transforms, animations and media queries. The rules are defined in the CSS Values and Units specification, and the browser behaviour is documented by MDN.

If you only need a quick rule of thumb: use rem for font sizes and most spacing so that text respects the reader's browser settings, use % or fr for flexible widths, use ch to limit line length, use dvh or svh for full-screen sections on phones, and use px for things that should not scale, such as hairline borders. To build a size that scales smoothly between two limits, combine units in clamp(). The clamp generator does the arithmetic, and the guide on fluid typography with CSS clamp() explains the formula. To turn pixel values into rem, use the unit converter for general conversions, or divide by the root font size (16px in most browsers by default).

The units you will use most

rem for text and spacing, % for widths, vw/dvh for viewport-based sizes, ch for line length, px for fixed details such as borders, and cqw/cqi inside components.

Absolute length units

Absolute units are fixed to each other. They are anchored to the CSS pixel, and the others are defined from it. They suit print layouts and details that must not scale. MDN warns that absolute lengths can cause accessibility problems for font sizes, because they do not scale with the user's settings, so prefer em or rem for text.

UnitMeaningNotes
pxOne CSS pixel. 1px = 1in / 96.On high-resolution screens one CSS pixel covers several device pixels.
cmOne centimetre. 1cm = 96px / 2.54.Mostly useful for print.
mmOne millimetre. 1mm = 1cm / 10.Mostly useful for print.
QA quarter of a millimetre. 1Q = 1cm / 40.Rare. The letter is upper case.
inOne inch. 1in = 2.54cm = 96px.Mostly useful for print.
pcOne pica. 1pc = 12pt = 1in / 6.Print typography.
ptOne point. 1pt = 1in / 72.Print typography.

Font-relative units

These units are measured against the font. Child elements inherit the computed value of a parent, not the relative expression itself.

UnitMeaningNotes
emThe computed font-size of the element. On the font-size property itself it means the inherited font size.Good for spacing that should scale with a component's own text. Nested em values multiply.
remThe font size of the root element, usually html. A common browser default is 16px, but users can change it.The usual choice for text and layout spacing. No compounding.
exThe x-height of the element's font. In many fonts 1ex is about 0.5em.Rare.
capThe cap height, the nominal height of capital letters, of the element's font.Aligning icons with capital letters.
chThe advance width of the glyph "0" (zero) in the element's font.Setting a readable line length, such as max-width: 65ch.
icThe advance of the CJK water ideograph (U+6C34) in the font.Sizing CJK text.
lhThe computed line-height of the element, as an absolute length.Spacing in whole lines for vertical rhythm.
rex, rcap, rch, ric, rlhThe same as ex, cap, ch, ic and lh, but measured on the root element's font.Fixed reference points that do not change inside nested components.

An example of compounding: if html is 16px and a list has font-size: 0.9em, a nested list inside it computes to 0.9 × 0.9 × 16px, about 13px. With 0.9rem every level stays at 14.4px.

Viewport units

Viewport units are percentages of the browser window (more exactly, the initial containing block). 1vw is 1% of the viewport width, so on an 800px-wide window 50vw is 400px, and on a 300px-tall window 70vh is 210px. The trouble on phones is that the visible height changes as the browser's address bar and toolbars slide in and out. To handle that, CSS defines three sets of viewport units, marked by a prefix.

Viewport unit sets

UnitsMeaningWhen to use
vw, vh, vi, vb, vmin, vmaxThe default viewport units. They are currently equivalent to the large viewport units (lvw, lvh and so on).Fine on desktop. On mobile, 100vh can be taller than the visible area.
svw, svh, svi, svb, svmin, svmaxSmall viewport: the smallest viewport, with browser interfaces expanded. Sizes are fixed unless the viewport itself is resized.Content fits fully visible, but there can be empty space when the interface retracts.
lvw, lvh, lvi, lvb, lvmin, lvmaxLarge viewport: the largest viewport, with browser interfaces retracted. Sizes are fixed.Fills the screen when the interface is hidden, but content may be hidden when it shows.
dvw, dvh, dvi, dvb, dvmin, dvmaxDynamic viewport: resizes automatically as the interface expands and retracts.Always fits exactly, but the size changes while scrolling, which can cause resizing and a performance cost.

What each viewport axis unit measures

UnitMeaningNotes
vw1% of the viewport width.Fluid type and widths, usually inside clamp().
vh1% of the viewport height.Full-height sections. Prefer svh or dvh on mobile.
vi1% of the size in the direction of the root element's inline axis.Writing-mode aware layouts.
vb1% of the size in the direction of the root element's block axis.Writing-mode aware layouts.
vmin1% of the smaller of the viewport width and height.Sizes that stay in proportion in both orientations.
vmax1% of the larger of the viewport width and height.Large decorative shapes.

A common pattern for a full-screen hero is min-height: 100vh; followed by min-height: 100dvh;. Browsers that do not understand dvh ignore the second line and keep the first. Note that viewport lengths are not valid inside @page declaration blocks.

Container query units

Container query units are relative to a query container, an ancestor you have set up with container-type. They let a component size itself from the space it is given rather than from the whole window, which makes it reusable in a sidebar and in a wide column. Set up a container with container-type: inline-size (query the inline dimension) or container-type: size (query both dimensions). The default value, normal, does not create a size container.

.card-wrap { container-type: inline-size; }
.card h2 { font-size: clamp(1rem, 4cqi, 2rem); }

Container query units

UnitMeaningNotes
cqw1% of the query container's width.For example, 50cqw in an 800px-wide container is 400px.
cqh1% of the query container's height.Needs a container with size containment.
cqi1% of the query container's inline size.Writing-mode aware. The usual choice with inline-size containers.
cqb1% of the query container's block size.Writing-mode aware.
cqmin1% of the smaller of the container's inline and block size.Proportional sizing in either shape.
cqmax1% of the larger of the container's inline and block size.Large decorative parts.

If no suitable container exists for the element, the container query unit falls back to the small viewport unit for that axis (sv*), so the layout still has a sensible value.

Percentages

A percentage is a number followed by %. It is always a percentage of something, and what that something is depends on the property. This is the most common source of surprises, so check the reference for the property you are using.

What a percentage refers to

PropertyPercentage ofNotes
widthThe width of the containing block.Also used for max-width and min-width.
heightThe height of the containing block.Only works when the containing block has a definite height.
paddingThe inline size (width in horizontal writing) of the containing block, even for top and bottom padding.Margins follow the same rule for percentages.
font-sizeThe font size of the parent element.200% of 18px is 36px.
line-heightThe element's own font size.A unitless number such as 1.5 is usually safer, because it scales with each element's font size.

Angle, time and resolution units

These units are not lengths, but you will meet them in transform, animation, transition and media queries. As with lengths, the unit cannot be left out, except that a plain 0 is allowed for lengths. For resolution, 0 without a unit is invalid.

Other units

UnitMeaningType
degDegrees. A full circle is 360deg.Angle
gradGradians. A full circle is 400grad.Angle
radRadians. A full circle is 2π rad, about 6.2832rad.Angle
turnTurns. A full circle is 1turn.Angle. Handy for rotations: rotate(0.25turn).
sSeconds, for example 1.5s.Time, for transitions and animations
msMilliseconds, for example 150ms.Time
dpiDots per inch.Resolution, for media queries
dpcmDots per centimetre.Resolution
dppx, xDots per px unit. 1dppx equals 96dpi. x is an alias.Resolution. (min-resolution: 2dppx) targets high-density screens.

Choosing a unit

Common mistakes

Sources