When applying styles to a container using container queries, you can use container query length units. These units specify a length relative to the dimensions of a query container. Components that use units of length relative to their container are more flexible to use in different containers without having to recalculate concrete length values. For more information, see Container queries.
cqw
-
Represents a percentage of the width of the query container. 1cqw
is 1% of the query container's width. For example, if the query container's width is 800px
, then a value of 50cqw
on a property will be 400px
.
cqh
-
Represents a percentage of the height of the query container. 1cqh
is 1% of the query container's height. For example, if the query container's height is 300px
, then a value of 10cqh
on a property will be 30px
.
cqi
-
Represents a percentage of the inline size of the query container. 1cqi
is 1% of the query container's inline size. For example, if the query container's inline size is 800px
, then a value of 50cqi
on a property will be 400px
.
cqb
-
Represents a percentage of the block size of the query container. 1cqb
is 1% of the query container's block size. For example, if the query container's block size is 300px
, then a value of 10cqb
on a property will be 30px
.
cqmin
-
Represents a percentage of the smaller value of either the query container's inline size or block size. 1cqmin
is 1% of the smaller value of either the query container's inline size or block size. For example, if the query container's inline size is 800px
and its block size is 300px
, then a value of 50cqmin
on a property will be 150px
.
cqmax
-
Represents a percentage of the larger value of either the query container's inline size or block size. 1cqmax
is 1% of the larger value of either the query container's inline size or block size. For example, if the query container's inline size is 800px
and its block size is 300px
, then a value of 50cqmax
on a property will be 400px
.
Absolute length units
Absolute length units represent a physical measurement when the physical properties of the output medium are known, such as for print layout. This is done by anchoring one of the units to a physical unit and then defining the others relative to it. The anchoring is done differently for low-resolution devices, such as screens, versus high-resolution devices, such as printers.
For low-dpi devices, the unit px
represents the physical reference pixel; other units are defined relative to it. Thus, 1in
is defined as 96px
, which equals 72pt
. The consequence of this definition is that on such devices, dimensions described in inches (in
), centimeters (cm
), or millimeters (mm
) don't necessarily match the size of the physical unit with the same name.
For high-dpi devices, inches (in
), centimeters (cm
), and millimeters (mm
) are the same as their physical counterparts. Therefore, the px
unit is defined relative to them (1/96 of 1in
).
Note: Many users increase their user agent's default font size to make text more legible. Absolute lengths can cause accessibility problems because they are fixed and do not scale according to user settings. For this reason, prefer relative lengths (such as em
or rem
) when setting font-size
.
px
-
One pixel. For screen displays, it traditionally represents one device pixel (dot). However, for printers and high-resolution screens, one CSS pixel implies multiple device pixels. 1px
= 1/96th of 1in
.
cm
-
One centimeter. 1cm
= 96px/2.54
.
mm
-
One millimeter. 1mm
= 1/10th of 1cm
.
Q
-
One quarter of a millimeter. 1Q
= 1/40th of 1cm
.
in
-
One inch. 1in
= 2.54cm
= 96px
.
pc
-
One pica. 1pc
= 12pt
= 1/6th of 1in
.
pt
-
One point. 1pt
= 1/72nd of 1in
.