CSS values and units
Every CSS declaration consists of a property/value pair. The value can take various forms depending on the property, such as a single integer, keyword, function, or a combination of different items; some values have units, while others do not. Every property also accepts the CSS-wide values. The CSS values and units module defines the data types — values and units — that CSS properties accept. This module also defines the CSS value definition syntax, or formal grammar, used to define the set of valid values for every CSS property and function.
Reference
Properties
Functions
abs()
acos()
asin()
atan()
atan2()
attr()
calc()
calc-size()
clamp()
cos()
exp()
hypot()
<ident()>
inherit()
log()
max()
min()
mod()
pow()
rem()
round()
sign()
sin()
sqrt()
tan()
<url()>
Additional functions, including calc-mix()
, crossorigin()
, first-valid()
, if()
, integrity()
, progress()
, random()
, random-item()
, referrerpolicy()
, sibling-count()
, sibling-index()
, src()
, type()
, and toggle()
, are defined in the specifications, but not yet implemented in browsers.
Data types
<angle-percentage>
<angle>
<animation-timeline>
<attr-name>
<attr-type>
<attr-unit>
<calc-keyword>
(e
,pi
,infinity
, NaN)<calc-size-basis>
<calc-sum>
<custom-ident>
<dashed-ident>
<dimension>
<easing-function>
<first-valid()>
<frequency>
<frequency-percentage>
<ident>
<integer>
<length-percentage>
<length>
<number>
<percentage>
<position>
<ratio>
<resolution>
<rounding-strategy>
(down
,up
,to-zero
)<string>
<syntax>
<time-percentage>
<time>
<url>
<url-modifier>
<view-timeline-name>
Units
%
(percentage)cap
ch
cm
deg
dpcm
dpi
dppx
dvb
dvh
dvi
dvmax
dvmin
dvw
em
ex
grad
Hz
ic
in
kHz
left
lh
lvb
lvh
lvi
lvmax
lvmin
lvw
mm
ms
pc
pi
pt
px
Q
rad
rcap
rch
rem
rex
ric
rlh
s
size
svb
svh
svi
svmax
svmin
svw
turn
up
vb
vh
vi
vmax
vmin
vw
x
Flex units (fr
) and container units (cqb
,cqh
,cqi
,cqmax
,cqmin
,cqw
) are defined in the CSS flexible box layout and CSS conditional rules modules, respectively.
Unit categorizations
- Absolute length units (
cm
,in
,mm
,pc
,pt
,px
,Q
) - Angle units (
deg
,grad
,rad
,turn
) - Default viewport units (
vb
,vh
,vi
,vmax
,vmin
,vw
) - Dynamic viewport units (
dvb
,dvh
,dvi
,dvmax
,dvmin
,dvw
) - Frequency units (
Hz
,kHz
) - Large viewport-percentage units (
lvb
,lvh
,lvi
,lvmax
,lvmin
,lvw
) - Local font-relative length units (
cap
,ch
,em
,ex
,ic
,lh
) - Physical units (
cm
,in
,mm
,pc
,pt
,Q
) - Relative length units (
cap
,ch
,em
,ex
,ic
,lh
,rem
,rlh
,vb
,vh
,vi
,vmax
,vmin
,vw
) - Resolution units (
dpcm
,dpi
,dppx
,x
) - Root font-relative length units (
rcap
,rch
,rem
,rex
,ric
,rlh
) - Small viewport-percentage unit (
svb
,svh
,svi
,svmax
,svmin
,svw
) - Time units (
ms
,s
) - Viewport units (
dvh
,dvw
,lvh
,lvw
,svh
,svw
,vb
,vh
,vi
,vmax
,vmin
,vw
) - Visual angle unit (
px
)
Key concepts
Guides
- CSS data types
-
Introduction to CSS data types that define typical values accepted by CSS properties and functions.
- Numeric data types
-
Overview of the numeric data types, including integers, numbers, percentages, and dimensions, along with relative and absolute dimensions, angles, and time units.
- Textual data types
-
Overview of the textual data types, including pre-defined keyword values, global CSS keyword values, and URLs.
- CSS value functions
-
Overview of the CSS statements that invoke special data processing or calculations to return a CSS value for a CSS property.
- Using CSS math functions
-
The CSS math functions that allow a property value to be written as a mathematical expression.
- Value definition syntax
-
The formal grammar used to define the set of valid values for CSS properties and functions.
- Learn: Values and units
-
A look at some of the most frequently used value types, what they are, and how they work.
Related
-
CSS flexible box layout module
<flex>
- Flex units (
fr
)
-
CSS conditional rules module
- Container units (
cqb
,cqh
,cqi
,cqmax
,cqmin
,cqw
)
- Container units (
-
CSS colors module
-
CSS images module
Specifications
Specification |
---|
CSS Values and Units Module Level 3 |
CSS Values and Units Module Level 4 |
CSS Values and Units Module Level 5 |
See also
- CSS syntax module
- CSS selectors module