Numbers & units
The numeric value types and the units that go with them: plain numbers and percentages, distances, angles, durations, resolutions and the grid's fr. Any of them can also be computed with calc() and the other math functions. Colours are under Colors; positions and shapes under Images, shapes & positions.
Numbers
<number>
A real number, with or without a fractional part, and optionally signed: 1, 0.5, -2, .75. Scientific notation such as 1e3 is also allowed.
| Definition | A sequence of digits, optionally with a sign, a decimal point and an exponent |
|---|---|
| Used by | line-height, opacity, flex, scale, zoom |
| Support | Chrome 1 · Firefox 1 · Safari 1 Scientific notation: Chrome 43 · Firefox 29 · Safari 10.1 |
| Spec | css-values-4 |
A property may restrict the range, written in its grammar as <number [0,∞]> for a non-negative number. A unitless line-height is a <number> that multiplies the font size, and is inherited as the factor rather than as a fixed length.
<integer>
A whole number, positive, negative or zero, with no fractional part: 3, -1, 0.
| Syntax | <number-token> |
|---|---|
| Used by | z-index, order, column-count, counter-increment, grid line numbers in grid-column |
| Support | Chrome 1 · Firefox 1 · Safari 1 |
| Spec | css-values-4 |
The grammar means a number token that has no decimal point and no exponent. 1.0 is a <number>, not an <integer>, so z-index: 1.0 is invalid.
<percentage>
A number followed by %, standing for a fraction of some reference value. Each property says what its percentages refer to, such as the containing block's width or the element's own font size.
| Definition | A <number> immediately followed by % |
|---|---|
| Used by | Most sizes through <length-percentage>; on its own in opacity, scale and font-width |
| Support | Chrome 1 · Firefox 1 · Safari 1 |
| Spec | css-values-4 |
<ratio>
Two non-negative numbers separated by a slash, most often an aspect ratio of width to height. If the second number is left out it is taken as 1.
| Syntax | <number [0,∞]> [ / <number [0,∞]> ]? |
|---|---|
| Used by | aspect-ratio, and the aspect-ratio media feature |
| Support | Chrome 3 · Firefox 3.5 · Safari 5 |
| Spec | css-values-4 |
aspect-ratio: 16 / 9;
aspect-ratio: 1; /* the same as 1 / 1 */
<dimension>
The general name for a number with a unit attached, such as 12px or 90deg. It is not used directly in property grammars; it is the shared form behind <length>, <angle>, <time>, <resolution> and <flex>.
| Definition | A <number> immediately followed by a unit identifier, with no space between them |
|---|---|
| Support | Chrome 1 · Firefox 1 · Safari 1 |
| Spec | css-values-4 |
Unit names are case-insensitive, so 10PX is the same as 10px.
Distance
<length>
A distance: a number followed by one of the length units below. A length of zero may be written without a unit; any other bare number is not a length.
| Definition | A <dimension> whose unit is a length unit, or the bare number 0 |
|---|---|
| Used by | width, margin, padding, border-width, font-size, gap, and most other sizes and offsets |
| Support | Chrome 1 · Firefox 1 · Safari 1 (later units are listed below) |
| Spec | css-values-4 |
| Unit | Equals | Support |
|---|---|---|
| Absolute | ||
px | One CSS pixel, 1/96 of an inch. Not tied to device pixels. | All browsers |
cm | One centimetre (about 37.8px). | All browsers |
mm | One millimetre, 1/10 of a centimetre. | All browsers |
Q | A quarter-millimetre, 1/40 of a centimetre. | Chrome 63 · Firefox 49 · Safari 13.1 |
in | One inch, 96px or 2.54cm. | All browsers |
pt | One point, 1/72 of an inch. | All browsers |
pc | One pica, 12pt or 1/6 of an inch. | All browsers |
| Font-relative | ||
em | The element's computed font size. In font-size itself, the parent's font size. | All browsers |
rem | The root element's font size. | Chrome 4 · Firefox 3.6 · Safari 5 |
ex | The x-height of the element's first available font. | All browsers |
rex | ex measured on the root element. | Chrome 111 · Firefox 147 · Safari 17.2 |
ch | The advance width of the digit 0 in the element's font. | Chrome 27 · Firefox 1 · Safari 7 |
rch | ch measured on the root element. | Chrome 111 · Firefox 147 · Safari 17.2 |
cap | The cap height: the height of capital letters in the element's font. | Chrome 118 · Firefox 97 · Safari 17.2 |
rcap | cap measured on the root element. | Chrome 118 · Firefox 147 · Safari 17.2 |
ic | The advance of the CJK ideograph 水 in the element's font, a full-width character cell. | Chrome 106 · Firefox 97 · Safari 15.4 |
ric | ic measured on the root element. | Chrome 111 · Firefox 147 · Safari 17.2 |
lh | The element's computed line-height. | Chrome 109 · Firefox 120 · Safari 16.4 |
rlh | The root element's line-height. | Chrome 111 · Firefox 120 · Safari 16.4 |
| Viewport | ||
vw, vh | 1% of the viewport's width or height. | Chrome 20 · Firefox 19 · Safari 6 |
vmin, vmax | 1% of the viewport's smaller or larger dimension. | Chrome 26 · Firefox 19 · Safari 7 |
vi, vb | 1% of the viewport in the root element's inline or block axis. | Chrome 108 · Firefox 101 · Safari 15.4 |
svw, svh, svi, svb, svmin, svmax | The same, measured on the small viewport: the size with the browser's expanding toolbars shown. | Chrome 108 · Firefox 101 · Safari 15.4 |
lvw, lvh, lvi, lvb, lvmin, lvmax | The same, measured on the large viewport: the size with those toolbars retracted. | Chrome 108 · Firefox 101 · Safari 15.4 |
dvw, dvh, dvi, dvb, dvmin, dvmax | The same, measured on the dynamic viewport, which changes as the toolbars show and hide. | Chrome 108 · Firefox 101 · Safari 15.4 |
| Container query | ||
cqw, cqh | 1% of the nearest query container's width or height. | Chrome 105 · Firefox 110 · Safari 16 |
cqi, cqb | 1% of the query container's inline or block size. | Chrome 105 · Firefox 110 · Safari 16 |
cqmin, cqmax | The smaller or larger of cqi and cqb. | Chrome 105 · Firefox 110 · Safari 16 |
On phones, 100vh is the large viewport and can run under the address bar; 100svh always fits, and 100dvh tracks the bar as it moves. Container units fall back to the small viewport units when there is no eligible container. See container-type.
min-height: 100svh;
max-width: 65ch;
padding-block: 1lh;
<length-percentage>
Either a <length> or a <percentage>, or a calc() that mixes the two, such as calc(100% - 2rem). The percentage resolves against whatever the property names.
| Syntax | [ <length> | <percentage> ] |
|---|---|
| Used by | width, margin-top, padding-top, inset, gap, border-radius |
| Support | Chrome 1 · Firefox 1 · Safari 1 |
| Spec | css-values-4 |
Angle & time
<angle>
A rotation or direction: a number followed by an angle unit. Positive angles turn clockwise. Some places, such as gradient angles, also accept a unitless 0.
| Definition | A <dimension> whose unit is an angle unit |
|---|---|
| Used by | rotate, rotate() and skew(), linear-gradient(), hue-rotate(), hues in colour functions, font-style: oblique |
| Support | Chrome 2 · Firefox 3.6 · Safari 4turn: Chrome 2 · Firefox 13 · Safari 4 |
| Spec | css-values-4 |
| Unit | Equals |
|---|---|
deg | Degrees; a full circle is 360deg. |
grad | Gradians; a full circle is 400grad. |
rad | Radians; a full circle is 2π, about 6.2832rad. |
turn | Turns; a full circle is 1turn. |
<angle-percentage>
Either an <angle> or a <percentage> of a full turn, as used by the colour stops of a conic gradient.
| Syntax | [ <angle> | <percentage> ] |
|---|---|
| Used by | Colour-stop positions in conic-gradient() and repeating-conic-gradient() |
| Support | Chrome 2 · Firefox 3.6 · Safari 4 |
| Spec | css-values-4 |
<time>
A duration or delay: a number followed by s (seconds) or ms (milliseconds). The unit is required, even for zero, so write 0s.
| Definition | A <dimension> whose unit is s or ms |
|---|---|
| Used by | transition-duration, transition-delay, animation-duration, animation-delay, interest-delay |
| Support | Chrome 1 · Firefox 4 · Safari 3.1 |
| Spec | css-values-4 |
| Unit | Equals |
|---|---|
s | Seconds. |
ms | Milliseconds; 1000ms is 1s. |
Durations cannot be negative. A negative delay is allowed and starts the animation part-way through.
Resolution & flex
<resolution>
The pixel density of an output device or an image: how many dots fit into a given length.
| Definition | A <dimension> whose unit is a resolution unit |
|---|---|
| Used by | The resolution media feature, and the density descriptors of image-set() |
| Support | Chrome 29 · Firefox 8 · Safari 16dppx: Chrome 29 · Firefox 16 · Safari 16x: Chrome 68 · Firefox 62 · Safari 16 |
| Spec | css-values-4 |
| Unit | Equals |
|---|---|
dpi | Dots per inch. |
dpcm | Dots per centimetre. |
dppx | Dots per CSS pixel. 1dppx is 96dpi. |
x | Another name for dppx. |
@media (resolution >= 2x) { … }
<flex>
A fraction of the free space in a grid container, written with the fr unit. After fixed and content-sized tracks are laid out, the leftover space is shared among the flexible tracks in proportion to their fr values.
| Definition | A <dimension> with the unit fr |
|---|---|
| Used by | grid-template-columns, grid-template-rows, grid-auto-columns, grid-auto-rows, and minmax() as its maximum |
| Support | Chrome 29 · Firefox 40 · Safari 10.1 |
| Spec | css-grid-2 |
A <flex> is not a <length>: it cannot be mixed with other units inside calc().
grid-template-columns: 200px 1fr 2fr;