inherit

  • Revision slug: CSS/inherit
  • Revision title: inherit
  • Revision id: 20174
  • Created:
  • Creator: DBaron
  • Is current revision? No
  • Comment /* Notes */

Revision Content

{{template.CSSRef()}}

Summary

inherit is a value that is allowed on every CSS property. It causes the element for which it is specified to take the computed value of the property from its parent element.

For inherited properties

For inherited properties, this reinforces the default behavior, and is only needed to override another rule. For example:

  /* make second-level headers green */
  h2 { color: green; }

  /* ...but leave those in the sidebar alone so they use their parent's color */
  #sidebar h2 { color: inherit; }

Note that in this example the h2 elements inside the sidebar might be different colors. For example, if one of them were the child of a div matched by the rule

 div#current { color: blue; }

it would be blue.

For non-inherited properties

For non-inherited properties, this specifies a behavior that typically makes relatively little sense.

Notes

Inheritance is always from the parent element in the document tree, even when the parent element is not the containing block.

Specifications

Browser Compatibility

See Also

initial

Revision Source

<p>
{{template.CSSRef()}}
</p>
<h3 name="Summary"> Summary </h3>
<p><b>inherit</b> is a value that is allowed on every CSS property.  It causes the element for which it is specified to take the <a href="en/CSS/computed_value">computed value</a> of the property from its parent element.
</p>
<h4 name="For_inherited_properties"> For inherited properties </h4>
<p>For <a href="en/CSS/inherited_and_non-inherited_properties">inherited properties</a>, this reinforces the default behavior, and is only needed to override another rule.  For example:
</p>
<pre>  /* make second-level headers green */
  h2 { color: green; }

  /* ...but leave those in the sidebar alone so they use their parent's color */
  #sidebar h2 { color: inherit; }
</pre>
<p>Note that in this example the <code>h2</code> elements inside the sidebar might be different colors.  For example, if one of them were the child of a div matched by the rule
</p>
<pre class="eval"> div#current { color: blue; }
</pre>
<p>it would be blue.
</p>
<h4 name="For_non-inherited_properties"> For non-inherited properties </h4>
<p>For <a href="en/CSS/inherited_and_non-inherited_properties">non-inherited properties</a>, this specifies a behavior that typically makes relatively little sense.
</p>
<h3 name="Notes"> Notes </h3>
<p>Inheritance is always from the parent element in the document tree, even when the parent element is not the containing block.
</p>
<h3 name="Specifications"> Specifications </h3>
<ul><li> <a class="external" href="http://www.w3.org/TR/CSS21/cascade.html#value-def-inherit">CSS 2.1</a>
</li></ul>
<h3 name="Browser_Compatibility"> Browser Compatibility </h3>
<h3 name="See_Also"> See Also </h3>
<p><a href="en/CSS/initial">initial</a>
</p>
Revert to this revision