Don't forget initial, inherit and unset
A little reminder of two CSS keywords too often underused: inherit (CSS2.1) and initial (CSS3), and a presentation of unset (CSS3), a combination of the two previous ones.
Inherit
- can be attached to any CSS property
- takes the property’s value specified in its first encountered parent
Using inherit, you can force inheritance for properties that are not inherited by nature (margin, padding, …).
Initial
- can be attached to any CSS property
- is used to reset a property to its initial value - or the one set by the user agent (
font-family
,color
, …) -
Initial override elements default CSS
Unset: combination of initial and inherit
At the time of writing, ‘unset’ only works with Chrome (41) and Firefox (27).
If the property is, by nature, inherited, unset runs inherit
.
If not it runs initial
.
color
is a property that naturally is inheritedmargin
is not inherited- because of [1], unset runs
inherit
- because of [2], unset runs
initial
. Thereforemargin-left
equals ‘0’
Check it out on jsfiddle.
All
At the time of writing, ‘all’ doesn’t work with safari.
The CSS all
property sets every properties of an element to its initial, inherited or unset value. Possible values are inherit | initial | unset
TL;DR : Why you should use it more
Less constant declarations
Using keywords, known as CSS-wide keywords, is interesting because – the way any variable would do - they “carry” values, which means we can declare values a minimum of time.
Better understanding of the code
CSS keywords help us and the team to interpret the code. In the previous example, the first block can be interpreted as : “We want all the links to be gray” while the second one means : “We want all the links to be the same colour as the content (regardless the colour)” - which is a much better way to analyse your UI -.