Skip to content
All references

CSS reference

CSS Units

Compare common relative and absolute CSS units and choose values that respond to text and viewport changes.

8 of 8 entries

Absolute

px

border-width: 1px;

A CSS pixel is a reference unit, not necessarily one hardware pixel.

Font-relative

rem

padding: 1.5rem;

Relative to the root font size.

Font-relative

em

font-size: 1.1em; padding: .75em;

For font-size, em uses the parent font size; for most other properties, the element’s own font size.

Font-relative

ch

max-width: 65ch;

Based on the advance width of the zero glyph; it is not an exact character count.

Context-relative

Percentage

width: 80%;

The reference quantity depends on the property and layout context.

Viewport

vw and vh

width: 90vw; min-height: 100vh;

One unit is one percent of viewport width or height; mobile browser UI can affect visible space.

Viewport

svh and dvh

min-height: 100svh;
height: 100dvh;

svh uses the small viewport; dvh tracks the dynamic viewport and can change as browser UI moves.

Grid

fr

grid-template-columns: 1fr 2fr;

Distributes fractions of available space in Grid; it is not a general length unit.