Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 512881 of inherit

  • Revision slug: Web/CSS/inherit
  • Revision title: inherit
  • Revision id: 512881
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment

Revision Content

{{ CSSRef() }}

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

For inherited properties, this reinforces the default behavior, and is only needed to override another rule.  For non-inherited properties, this specifies a behavior that typically makes relatively little sense and you may consider using {{cssxref("initial")}} instead, or {{cssxref("unset")}} on the {{cssxref("all")}} property.

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

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; }

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.

Specifications

Specification Status Comment
{{ SpecName('CSS3 Values', "#common-keywords", "inherit") }} {{ Spec2('CSS3 Values') }} No significant change from {{ SpecName('CSS2.1') }}.
{{ SpecName('CSS2.1', "#value-def-inherit", "inherit") }} {{ Spec2('CSS2.1') }} Initial definition.

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 1.0 {{CompatGeckoDesktop("1.0")}} 8.0 4.0 1.0 (85)
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support 1.0 {{CompatGeckoMobile("1.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatVersionUnknown}}

See also

  • Inheritance
  • The {{cssxref("all")}} CSS property.
  • The CSS-wide property values: {{cssxref("initial")}}, {{cssxref("inherit")}} and {{cssxref("unset")}}.

Revision Source

<p>{{ CSSRef() }}</p>
<p>The <code>inherit</code> CSS-value causes the element for which it is specified to take the <a href="/en-US/docs/Web/CSS/computed_value">computed value</a> of the property from its parent element. It is allowed on every CSS property.</p>
<p>For <a href="/en/CSS/inheritance" title="en/CSS/inheritance">inherited properties</a>, this reinforces the default behavior, and is only needed to override another rule.&nbsp; For <a href="/en/CSS/inheritance" title="en/CSS/inheritance">non-inherited properties</a>, this specifies a behavior that typically makes relatively little sense and you may consider using {{cssxref("initial")}} instead, or {{cssxref("unset")}} on the {{cssxref("all")}} property.</p>
<div class="note">
 <p>Inheritance is always from the parent element in the document tree, even when the parent element is not the containing block.</p>
</div>
<h2 id="Example">Example</h2>
<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>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>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
 <thead>
  <tr>
   <th>Specification</th>
   <th>Status</th>
   <th>Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{ SpecName('CSS3 Values', "#common-keywords", "inherit") }}</td>
   <td>{{ Spec2('CSS3 Values') }}</td>
   <td>No significant change from {{ SpecName('CSS2.1') }}.</td>
  </tr>
  <tr style="vertical-align: top;">
   <td style="vertical-align: top;">{{ SpecName('CSS2.1', "#value-def-inherit", "inherit") }}</td>
   <td style="vertical-align: top;">{{ Spec2('CSS2.1') }}</td>
   <td style="vertical-align: top;">Initial definition.</td>
  </tr>
 </tbody>
</table>
<h2 id="Browser_Compatibility" name="Browser_Compatibility">Browser compatibility</h2>
<div>
 {{CompatibilityTable}}</div>
<div id="compat-desktop">
 <table class="compat-table">
  <tbody>
   <tr>
    <th>Feature</th>
    <th>Chrome</th>
    <th>Firefox (Gecko)</th>
    <th>Internet Explorer</th>
    <th>Opera</th>
    <th>Safari (WebKit)</th>
   </tr>
   <tr>
    <td>Basic support</td>
    <td>1.0</td>
    <td>{{CompatGeckoDesktop("1.0")}}</td>
    <td>8.0</td>
    <td>4.0</td>
    <td>1.0 (85)</td>
   </tr>
  </tbody>
 </table>
</div>
<div id="compat-mobile">
 <table class="compat-table">
  <tbody>
   <tr>
    <th>Feature</th>
    <th>Android</th>
    <th>Firefox Mobile (Gecko)</th>
    <th>IE Phone</th>
    <th>Opera Mobile</th>
    <th>Safari Mobile</th>
   </tr>
   <tr>
    <td>Basic support</td>
    <td>1.0</td>
    <td>{{CompatGeckoMobile("1.0")}}</td>
    <td>{{CompatUnknown}}</td>
    <td>{{CompatUnknown}}</td>
    <td>{{CompatVersionUnknown}}</td>
   </tr>
  </tbody>
 </table>
</div>
<h2 id="See_Also" name="See_Also">See also</h2>
<ul>
 <li><a class="internal" href="/en-US/docs/CSS/inheritance" title="es/CSS/inheritance">Inheritance</a></li>
 <li>The {{cssxref("all")}} CSS property.</li>
 <li>
  <p>The CSS-wide property values: {{cssxref("initial")}}, {{cssxref("inherit")}} and {{cssxref("unset")}}.</p>
 </li>
</ul>
Revert to this revision