Inherit - Value CSS
Summary of characteristics of the inherit
value
The value inherit
.
When a property is set to the inherit
value, it takes on the same value as the equivalent property of the parent element.
The parent element is the one that, in the DOM tree, is above the element in question.
The inherit
value is mostly used to re-enable the inheritance mechanism when a property has previously been set to a different value.
It can also enable inheritance on a property that is not inherited by default.
See also unset
, initial
, revert
, and revert-layer
.
The inherit
value and relative values.
Relative values are values that are calculated from another value. The most common example is the percentage.
Typically, the inherit
value retrieves the calculated value of the parent element. The calculation is therefore not redone on the element itself.
For example, consider a font size set to 2em
on the parent element.
Which gives let's say 24 pixels.
Child elements will inherit the calculated value (24 pixels) and not the 2em, which would ultimately give a 48 pixel font on kids.
There are, however, exceptions to this rule. Dimension properties (width
, margin
, etc.)
inherit the defined value, which therefore causes the children to recalculate the value in order to determine the value.
Example :
25%
inherit
. We can clearly see that the calculation has been redone
since the left margin does not have the same value as that of the parent element.
Examples and practical cases.
Example 1.
Force the inheritance mechanism on a property that by default does not inherit its value. This is the case of background-color
.
#example1
Parent Block.
#exemple1a
The background color of this block has not been changed. Its initial value is
transparent
.
#example1b
The background color of this block is set to
inherit
.
The color is therefore the same as that of the parent block.
Browser support (compatibility).
The inherit
value is very well recognized by all current browsers.
inherit
value
Browsers on computers :
Mobile browsers :
Outdated or marginal browsers :

Internet Explorer

KaiOS Browser

Opéra Mobile

Chrome

Edge

Opéra

Safari

Safari sur IOS

Androïd Brower

Chrome pour Androïd

Firefox pour Androïd

Samsung Internet

Firefox

Baidu Browser

QQ Browser

UC Browser pour Androïd

Opéra mini
The history of the inherit
property.
The inherit
value is also cited in the CSS Values and Units level 3 and 4 modules.
-
Cascading Style Sheets Level 2 - Revision 1 Specification
Introduction of theinherit
value to force inheritance of the parent's value.November 04, 1997Working Draft.March 24, 1998Proposed for recommendation.May 11, 1998Recommendation . -
CSS Cascading and Inheritance Level 3
No change to theinherit
value.July 13, 2001Working Draft.October 03, 2013Candidate Recommendation.December 22, 2020Proposed for recommendation.February 11, 2021Recommendation . -
CSS Cascading and Inheritance Level 4
No change to theinherit
value.April 21, 2015Working Draft.January 14, 2016Candidate Recommendation. -
CSS Cascading and Inheritance Level 5
No change to theinherit
value.January 19, 2021Working Draft.January 13, 2022Candidate Recommendation.
See also, about values.
The CSS specifications published by the W3C are organized into modules.
The inherit
property is part of the CSS Cascading and Inheritance module.
The following definitions are also described in this same module.
Properties:
At-rules:

