The Word âValueâ in CSS
I loved this post by Karl Dubost which outlines how overloaded the word âvalueâ can be in CSS.
When you say âvalueâ in CSS, you might think you know what it means. But if you look closer â especially at the spec â youâll find there are lots of different meanings for the word âvalueâ in CSS, each one different than the next.
If you say width: 100px
, it seems readily apparent what the âvalueâ is for width
. But if you write width: auto
what would you say if someone asks you, âWhatâs the value?â Are they referring to whatâs written in the CSS, i.e. auto
? Or are they referring to what auto
ends up being once the browser calculates it and renders it on screen? You can see how things can get murky really fast (and we havenât even mentioned how values cascade yet).
To further illustrate this point, take a look at each of these rules ask yourself: what would I say if somebody asked me, âWhatâs the value here?â
font-size: 2em
width: calc(100% - 14px)
color: red
background: var(--color-brand)
font-weight: bolder
Youâd probably say, âWell that depends on what you mean by the word âvalueâ!â
Thatâs kind of the whole point of the article: there are lots of qualified terms for the word âvalueâ in the spec. These are the ones outlined by Karl:
- Actual value
- Used value
- Computed value
- Specified value
- Cascaded value
- Declared value
- Initial value
- Resolved value
- Relative value
- Absolute value
Phew! Thatâs a lot of values.