CSS <dimension> Data Type
The <dimension> data type is a number followed by a unit, such as 10px, 45deg, 300ms or 2fr. Lengths, angles, times and frequencies are all dimensions.
Description
The <dimension> CSS data type represents a <number> immediately followed by a unit, such as 10px, 45deg, 300ms or 2fr. It is a general category rather than a type you normally write in a property definition: every specific measurement type in CSS, including <length>, <angle>, <time>, <frequency>, <resolution> and <flex>, is a kind of <dimension>.
The unit is what gives a dimension its meaning. The same number can mean very different things depending on the unit attached: 2s is a duration, 2rem is a length and 2turn is an angle. There must be no space between the number and the unit, so 10 px is invalid. Units are case-insensitive, which means 10PX and 10px are the same value, though lowercase is the convention. A value of zero still needs its unit in most places, with lengths being the common exception where 0 may be written without one.
Percentages look similar, but <percentage> is a separate type, because a percentage is always relative to some other value rather than being a measurement in its own right. Many properties accept both, which is why combined types such as <length-percentage> and <angle-percentage> exist. Dimensions can also be combined inside calc() as long as they are of the same kind.
Examples:
.card {
width: 320px; /* <length> */
padding: 1.5rem; /* <length> */
transform: rotate(3deg); /* <angle> */
transition: transform 250ms ease; /* <time> */
}
.grid {
display: grid;
grid-template-columns: 1fr 2fr; /* <flex> */
}
@media (min-resolution: 2dppx) { /* <resolution> */
.logo { background-image: url("logo@2x.png"); }
}
Knowing that all these types share the <dimension> form makes it easier to read property syntax and to understand why mixing units of different kinds in a calculation is invalid.
Interactive Demo
Syntax
<dimension> = <number><unit>
Values
- <length>A distance, using units such as px, em, rem, vw, vh, cm or in.
- <angle>A rotation, using the units deg, grad, rad or turn.
- <time>A duration, using the units s or ms.
- <frequency>A rate, using the units Hz or kHz.
- <resolution>A pixel density, using the units dpi, dpcm, dppx or x.
- <flex>A fraction of the free space in a grid container, using the unit fr.
Example
Browser Support
The following information will show you the current browser support for the CSS dimension data type. Hover over a browser icon to see the version that first introduced support for this CSS data type.
Desktop





Tablets & Mobile





