CSS Reference ยท Custom Properties, Cascade and Global Keywords
The initial keyword
Reference for the CSS initial keyword: it resets a property to its specification default, ignoring the browser style sheet. Examples and pitfalls.
The initial keyword sets a property to its initial value, the default defined in the CSS specification for that property. It works on every CSS property and ignores both inheritance and the browser's default style sheet.
That last point trips people up. The specification says display starts as inline, so div { display: initial } makes a <div> inline, even though browsers normally style <div> as block. If you want the browser's own default instead, use revert.
.reset { color: initial; margin: initial; }
Try it
Syntax
property: initial;
- Works on: every property, including shorthands (all their longhands reset)
- Result: the property's initial value from its specification, which is listed on every property page in this reference
- Custom properties:
--x: initialsets the property to the guaranteed-invalid value, as if it was never set
Values
| Syntax | Description |
|---|---|
property: initial |
Uses the specified default. For color that is the UA-dependent "canvas text" color, usually black; for margin it is 0; for display it is inline. |
all: initial |
Resets every property of the element; see all. |
Usage notes
- Not the same as the browser default. Browser style sheets give
h1a big bold font andula left margin.initialremoves those too, because it goes to the specification value, not the user-agent style sheet value. - Beats inheritance.
initialoncolorstops the value inherited from the parent, whichunsetwould not (unsetinherits for inherited properties). - Good fits: clearing an earlier declaration in a state rule (
margin-left: initial), or breaking the link to an inherited custom property. - Prefer
unsetorrevertwhen you just want to "forget my styling". They are less surprising.
Browser support
Supported in all browsers.
Related
inherit,unset,revertandrevert-layerall- Lessons: Global values, Inheritance