CSS inherit / initial
- type
- keyword values
- applies to
- any property
- inherits
- n/a
- common values
- inherit, initial, unset, revert
Where it goes
As the value of a property. Common: button, input { font: inherit; color: inherit } so form fields match the page, and a { color: inherit }.
Example
button, input, select {
font: inherit;
color: inherit;
}
a { color: inherit; }
.plain { all: unset; cursor: pointer; }Common mistakes
- Expecting initial to give the browser default. initial for display is inline, not the block the browser gives a <div>. Use revert for the browser default.
- Setting font-size on <body> and wondering why inputs ignore it. Form fields do not inherit fonts by default in most browsers. font: inherit fixes it.
- Using all: unset on a button and losing the focus ring, the cursor and keyboard behavior. Add outline on :focus-visible and cursor: pointer back afterwards.