Computed value

  • Revision slug: CSS/computed_value
  • Revision title: Computed value
  • Revision id: 68794
  • Created:
  • Creator: DBaron
  • Is current revision? No
  • Comment

Revision Content

{{template.CSSRef()}}

Summary

The computed value of a CSS property is computed from the specified value by:

  • handling the special values inherit and initial, and
  • doing the computation described in the "Computed value" line in the property's summary.

The computation needed to reach the "Computed value" for the property typically involves converting relative values (such as those in 'em' units or percentages) to absolute values.

For example, if an element has specified values font-size: 16px and padding-top: 2em, then the computed value of padding-top is 32px (double the font size).

However, for some properties (those where percentages are relative to something that may require layout to determine, such as width, margin-right, text-indent, and top), percentage specified values turn into percentage computed values. Additionally, unitless numbers specified on the line-height property become the computed value, as specified. These relative values that remain in the computed value become absolute when the used value is determined.

The main use of the computed value (other than as a step between the specified value and used value) is inheritance, including the inherit keyword.

Notes

The getComputedStyle DOM API returns the used value, not the computed value.

See Also

specified value, used value, actual value

Revision Source

<p>
{{template.CSSRef()}}
</p>
<h3 name="Summary"> Summary </h3>
<p>The <b>computed value</b> of a CSS property is computed from the <a href="en/CSS/specified_value">specified value</a> by:
</p>
<ul><li> handling the special values <code><a href="en/CSS/inherit">inherit</a></code> and <code><a href="en/CSS/initial">initial</a></code>, and
</li><li> doing the computation described in the "Computed value" line in the property's summary.
</li></ul>
<p>The computation needed to reach the "Computed value" for the property typically involves converting relative values (such as those in 'em' units or percentages) to absolute values.
</p><p>For example, if an element has specified values <code>font-size: 16px</code> and <code>padding-top: 2em</code>, then the computed value of <code>padding-top</code> is <code>32px</code> (double the font size).
</p><p>However, for some properties (those where percentages are relative to something that may require layout to determine, such as <a href="en/CSS/width">width</a>, <a href="en/CSS/margin-right">margin-right</a>, <a href="en/CSS/text-indent">text-indent</a>, and <a href="en/CSS/top">top</a>), percentage specified values turn into percentage computed values.  Additionally, unitless numbers specified on the <a href="en/CSS/line-height">line-height</a> property become the computed value, as specified.  These relative values that remain in the computed value become absolute when the <a href="en/CSS/used_value">used value</a> is determined.
</p><p>The main use of the <a href="en/CSS/computed_value">computed value</a> (other than as a step between the <a href="en/CSS/specified_value">specified value</a> and <a href="en/CSS/used_value">used value</a>) is <a href="en/CSS/inherited_and_non-inherited_properties">inheritance</a>, including the <a href="en/CSS/inherit">inherit</a> keyword.
</p>
<h3 name="Notes"> Notes </h3>
<p>The <a href="en/DOM/window.getComputedStyle">getComputedStyle</a> DOM API returns the <a href="en/CSS/used_value">used value</a>, not the <a href="en/CSS/computed_value">computed value</a>.
</p>
<h3 name="See_Also"> See Also </h3>
<p><a href="en/CSS/specified_value">specified value</a>, <a href="en/CSS/used_value">used value</a>, <a href="en/CSS/actual_value">actual value</a>
</p>
Revert to this revision