Some properties are inherited. If no rule sets them on an element, the element takes its parent's computed value. The computed value is the final value the browser worked out for the parent.
- Text properties inherit, such as
color,font-family,line-heightandvisibility. - Box properties do not inherit, such as
margin,border,widthandbackground. They fall back to their initial value.
Four keywords control this:
inheritforces the parent's value, even for properties that don't normally inherit.initialuses the property's initial value from the CSS spec. This can surprise you:display: initialisinline, notblock.unsetacts likeinheritfor inherited properties, and likeinitialfor the rest.revertgoes back to the value the previous origin would give. An origin is a source of styles, and the previous one is usually the browser's default stylesheet. Sodisplay: reverton adivgivesblock.
There is also revert-layer, which goes back to the previous cascade layer.
- Text-related properties inherit, but box properties don't.
inherituses the parent's value.initialuses the initial value from the spec.unsetacts asinheritorinitial, depending on whether the property inherits.revertgoes back to the browser default (the previous origin).revert-layerdoes the same for layers.
Read more
- Inheritance (MDN) (https://developer.mozilla.org/en-US/docs/Web/CSS/inheritance)developer.mozilla.org
- revert (MDN) (https://developer.mozilla.org/en-US/docs/Web/CSS/revert)developer.mozilla.org