padding

  • Revision slug: CSS/padding
  • Revision title: padding
  • Revision id: 25438
  • Created:
  • Creator: grendel
  • Is current revision? No
  • Comment Removed old compat table; 26 words removed

Revision Content

{{ CSSRef() }}

Summary

The padding CSS property sets the required padding space on all sides of an element. The padding area is the space between the content of the element and its border. Negative values are not allowed.

The padding property is a shortcut to avoid setting each side separately (padding-top, padding-right, padding-bottom, padding-left).

  • {{ Xref_cssinitial() }}: 0
  • Applies to: all elements (except table-*-group, table-row and table-column)
  • {{ Xref_cssinherited() }}: no
  • Percentages: relative to the width of the containing block
  • Media: {{ Xref_cssvisual() }}
  • {{ Xref_csscomputed() }}: the percentage as specified or the absolute length

Syntax

padding:   [ {{ Xref_csslength() }}| {{ Xref_csspercentage() }}] {1,4}

Values

Specifies one, two, tree or four of the following values:

<length>
Specifies a positive fixed width. See {{ Xref_csslength() }} for details.
<percentage>
With respect to the width of the containing block.
  • One single value applies to all 4 sides
  • Two values apply to 1. top and bottom and 2. to the left and right side
  • Three values apply to 1. top, 2. right and left and 3. to the bottom side
  • Four values apply to 1. top, 2. right, 3. bottom and 4. to the left side

Examples

 padding: 5%;               /* on all sides 5% padding */
 padding: 10px;              /* on all sides 10px padding */
 padding: 10px 20px;         /*  top and bottom 10px padding  */
                             /*  left and right 20px padding  */
 padding: 10px 3% 20px;      /*  top 10px padding          */
                             /*  left and right 3% padding */
                             /*  bottom 20px padding       */
 padding: 1em 3px 30px 5px;  /*  top    1em  padding  */
                             /*  right  3px  padding  */
                             /*  bottom 30px padding  */
                             /*  left   5px  padding  */

border:outset; padding:5% 1em;

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 1.0 1.0 (1.0) 4.0 3.5 1.0 (85)
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}

Specifications

See also

{{ languages( { "de": "de/CSS/padding", "ja": "ja/CSS/padding" } ) }}

Revision Source

<p>{{ CSSRef() }}</p>
<h3>Summary</h3>
<p>The<code> padding </code>CSS property sets the required padding space on all sides of an element. The padding area is the space between the content of the element and its border. Negative values are not allowed.</p>
<p>The<code> padding </code>property is a shortcut to avoid setting each side separately (<code>padding-top, padding-right, padding-bottom, padding-left</code>).</p>
<ul> <li>{{ Xref_cssinitial() }}:<code> 0</code></li> <li>Applies to: all elements (except <code> table-*-group</code>, <code>table-row</code> and <code>table-column</code>)</li> <li>{{ Xref_cssinherited() }}: no</li> <li>Percentages: relative to the<strong> width </strong>of the containing block</li> <li>Media: {{ Xref_cssvisual() }}</li> <li>{{ Xref_csscomputed() }}: the percentage as specified or the absolute length</li>
</ul>
<h3>Syntax</h3>
<pre class="eval">padding:   [ {{ Xref_csslength() }}| {{ Xref_csspercentage() }}] {1,4}
</pre>
<h3>Values</h3>
<p>Specifies one, two, tree or four of the following values:</p>
<dl> <dt>&lt;length&gt;</dt> <dd>Specifies a positive fixed width. See {{ Xref_csslength() }} for details.</dd> <dt>&lt;percentage&gt;</dt> <dd>With respect to the<strong> width </strong>of the containing block.</dd>
</dl>
<ul> <li><strong>One</strong> single value applies to <em>all 4 sides</em></li> <li><strong>Two</strong> values apply to <strong>1.</strong> <em>top and bottom</em> and <strong>2.</strong> to the <em>left and right</em> side</li> <li><strong>Three</strong> values apply to <strong>1.</strong> <em>top</em>, <strong>2.</strong> <em>right and left</em> and <strong>3.</strong> to the <em>bottom</em> side</li> <li><strong>Four</strong> values apply to <strong>1.</strong> <em>top</em>, <strong>2.</strong> <em>right</em>, <strong>3.</strong> <em>bottom</em> and <strong>4.</strong> to the <em>left</em> side</li>
</ul>
<h3>Examples</h3>
<pre> padding: 5%;               /* on all sides 5% padding */
</pre>
<pre> padding: 10px;              /* on all sides 10px padding */
</pre>
<pre> padding: 10px 20px;         /*  top and bottom 10px padding  */
                             /*  left and right 20px padding  */
</pre>
<pre> padding: 10px 3% 20px;      /*  top 10px padding          */
                             /*  left and right 3% padding */
                             /*  bottom 20px padding       */
</pre>
<pre> padding: 1em 3px 30px 5px;  /*  top    1em  padding  */
                             /*  right  3px  padding  */
                             /*  bottom 30px padding  */
                             /*  left   5px  padding  */
</pre>
<p style="border:outset; padding:5% 1em;">border:outset; padding:5% 1em;</p>
<h3 name="Browser_Compatibility">Browser compatibility</h3>
<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 support</td> <td>1.0</td> <td>1.0 (1.0)</td> <td>4.0</td> <td>3.5</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>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> </tr> </tbody>
</table>
</div>
<h3>Specifications</h3>
<ul> <li><a class="external" href="http://www.w3.org/TR/CSS21/box.html#padding-properties">CSS 2.1 Box #padding</a></li>
</ul>
<h3>See also</h3>
<ul> <li>{{ CSS_Reference:Padding() }}</li> <li><a class="internal" href="/en/CSS/box_model" title="en/CSS/box model">CSS Box Model</a></li>
</ul>
<p>{{ languages( { "de": "de/CSS/padding", "ja": "ja/CSS/padding" } ) }}</p>
Revert to this revision