<percentage>

  • Revision slug: CSS/percentage
  • Revision title: percentage
  • Revision id: 69304
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment 1 words added, 3 words removed

Revision Content

{{ CSSRef() }}

Summary

The <percentage> CSS data types represent a percentage value. Many CSS properties can take percentage values, often to define sizes in terms of parent objects. Percentages are formed by a {{ Xref_cssnumber() }} immediately followed by the percentage sign %. Like for all unit in CSS, there is no space between the '%' and the number.

Many length properties use percentages, such as {{ Cssxref("width") }}, {{ Cssxref("margin") }} and {{ Cssxref("padding") }}. Percentages can also be seen in {{ Cssxref("font-size") }}, where the size of the text is directly related to the size of its parent.

Note: only calculated values are inherited. So, even if a percentage value is used on the parent property, a real value, like a width in pixel for a {{ Xref_csslength() }} value, will be accessible on the inherited property, not the percentage value.

Examples

<div style="background-color:#0000FF;">
  <div style="width:50%;margin-left:20%;background-color:#00FF00;">Width: 50%, Left margin: 20%</div>
  <div style="width:30%;margin-left:60%;background-color:#FF0000;">Width: 30%, Left margin: 60%</div>
</div> 

The above HTML will output:

Width: 50%, Left margin: 20%
Width: 30%, Left margin: 60%

 

<div style="font-size:18px;">
  Full size text (18px)
  <span style="font-size:50%;">50%</span>
  <span style="font-size:200%;">200%</span>
</div> 

The above HTML will output:

Full size text (18px) 50% 200%

Specifications

Specification Status Comment
CSS Values and Units Level 3 {{ Spec2('CSS3 Values') }} No significant change from CSS Level 2 (Revision 1)
CSS Level 2 (Revision 1) {{ Spec2('CSS2.1') }} No change from CSS Level 1
CSS Level 1 {{ Spec2('CSS1') }}  

Browser Compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
basic 1.0 1.0 (1.0) <=5.0 yes 1.0 (85)
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support yes yes yes yes yes

See also

{{ languages( { "fr": "fr/CSS/pourcentage" } ) }}

Revision Source

<p>{{ CSSRef() }}</p>
<h2 name="Summary">Summary</h2>
<p>The <code>&lt;percentage&gt;</code> <a href="/en/CSS" title="CSS">CSS</a> data types represent a percentage value. Many <a href="/en/CSS_Reference" title="en/CSS_Reference">CSS properties</a> can take percentage values, often to define sizes in terms of parent objects. Percentages are formed by a {{ Xref_cssnumber() }} immediately followed by the percentage sign <code>%</code>. Like for all unit in CSS, there is no space between the '%' and the number.</p>
<p>Many length properties use percentages, such as {{ Cssxref("width") }}, {{ Cssxref("margin") }} and {{ Cssxref("padding") }}. Percentages can also be seen in {{ Cssxref("font-size") }}, where the size of the text is directly related to the size of its parent.</p>
<div class="note"><strong>Note:</strong> only calculated values are inherited. So, even if a percentage value is used on the parent property, a real value, like a width in pixel for a {{ Xref_csslength() }} value, will be accessible on the inherited property, not the percentage value.</div><h2>Examples</h2>
<pre class="brush: html">&lt;div style="background-color:#0000FF;"&gt;
  &lt;div style="width:50%;margin-left:20%;background-color:#00FF00;"&gt;Width: 50%, Left margin: 20%&lt;/div&gt;
  &lt;div style="width:30%;margin-left:60%;background-color:#FF0000;"&gt;Width: 30%, Left margin: 60%&lt;/div&gt;
&lt;/div&gt; 
</pre>
<p>The above HTML will output:</p>
<div style="background-color:#0000FF;"> <div style="width:50%;margin-left:20%;background-color:#00FF00;">Width: 50%, Left margin: 20%</div> <div style="width:30%;margin-left:60%;background-color:#FF0000;">Width: 30%, Left margin: 60%</div>
</div>
<p> </p>
<pre class="brush: html">&lt;div style="font-size:18px;"&gt;
  Full size text (18px)
  &lt;span style="font-size:50%;"&gt;50%&lt;/span&gt;
  &lt;span style="font-size:200%;"&gt;200%&lt;/span&gt;
&lt;/div&gt; 
</pre>
<p>The above HTML will output:</p>
<div style="font-size:18px;">Full size text (18px) <span style="font-size:50%">50%</span> <span style="font-size:200%">200%</span></div>
<h2 name="Specifications">Specifications</h2>
<table border="1" cellpadding="1" cellspacing="1" style="width: 1053px; border-style: solid; border-width: 1px; height: 75px; border-color: rgb(0,0,0);"> <thead> <tr style="background-color: rgb(255, 204, 255);"> <th scope="col">Specification</th> <th scope="col">Status</th> <th scope="col">Comment</th> </tr> </thead> <tbody> <tr> <td><a class="external" href="http://www.w3.org/TR/css3-values/#percentages" title="http://www.w3.org/TR/css3-values/#percentages">CSS Values and Units Level 3</a></td> <td>{{ Spec2('CSS3 Values') }}</td> <td>No significant change from CSS Level 2 (Revision 1)</td> </tr> <tr style="vertical-align: top;"> <td style="vertical-align: top;"><a class="external" href="http://www.w3.org/TR/CSS2/syndata.html#percentage-units" title="http://www.w3.org/TR/CSS2/syndata.html#percentage-units">CSS Level 2 (Revision 1)</a></td> <td style="vertical-align: top;">{{ Spec2('CSS2.1') }}</td> <td style="vertical-align: top;">No change from CSS Level 1</td> </tr> <tr> <td style="vertical-align: top;"><a class="external" href="http://www.w3.org/TR/CSS1/#percentage-units" title="http://www.w3.org/TR/CSS1/#percentage-units">CSS Level 1</a></td> <td style="vertical-align: top;">{{ Spec2('CSS1') }}</td> <td style="vertical-align: top;"> </td> </tr> </tbody>
</table>
<h2 name="Browser_Compatibility">Browser Compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<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</td> <td>1.0</td> <td>1.0 (1.0)</td> <td>&lt;=5.0</td> <td>yes</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>yes</td> <td>yes</td> <td>yes</td> <td>yes</td> <td>yes</td> </tr> </tbody> </table>
</div>
<h2 name="See_also">See also</h2>
<p>{{ languages( { "fr": "fr/CSS/pourcentage" } ) }}</p>
Revert to this revision