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 1046648 of margin-top

  • Revision slug: Web/CSS/margin-top
  • Revision title: margin-top
  • Revision id: 1046648
  • Created:
  • Creator: Simplexible
  • Is current revision? Yes
  • Comment {{xref_csspercentage}} replaced with {{cssxref("<percentage>")}}

Revision Content

{{CSSRef}}

Summary

The effect of the CSS margin-top property on the element boxThe margin-top CSS property of an element sets the margin space required on the top of an element. A negative value is also allowed.

This property has no effect on non-replaced inline elements, like {{HTMLElement("tt")}} or {{HTMLElement("span")}}.

{{cssinfo}}

Syntax

/* <length> values */
margin-top: 10px;        /* An absolute length */
margin-top: 1em;         /* A length relative to the text size */
margin-top: 5%;          /* A margin relative to the nearest block container's width */

/* Keyword values */
margin-top: auto;

/* Global values */
margin-top: inherit;
margin-top: initial;
margin-top: unset;

Values

<length>
Specifies a fixed width. See {{cssxref("<length>")}} for possible values.
<percentage>
A {{cssxref("<percentage>")}} always relative to the width of the containing block.
auto
See {{cssxref("margin")}}.

Formal syntax

{{csssyntax}}

Examples

.content { margin-top:   5%; }
.sidebox { margin-top: 10px; }
.logo    { margin-top: -5px; }
#footer  { margin-top:  1em; } 

Specifications

Specification Status Comment
{{SpecName('CSS3 Box', '#the-margin', 'margin-top')}} {{Spec2('CSS3 Box')}} No significant change
{{SpecName('CSS3 Transitions', '#animatable-css', 'margin-top')}} {{Spec2('CSS3 Transitions')}} Defines margin-top as animatable.
{{SpecName('CSS2.1', 'box.html#margin-properties', 'margin-top')}} {{Spec2('CSS2.1')}} Removes its effect on inline elements.
{{SpecName('CSS1', '#margin-top', 'margin-top')}} {{Spec2('CSS1')}} Initial definition

Browser compatibility

{{CompatibilityTable()}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 1.0 {{CompatGeckoDesktop("1")}} 3.0 3.5 1.0 (85)
auto value 1.0 {{CompatGeckoDesktop("1")}} 6.0 (strict mode) 3.5 1.0 (85)
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support 1.0 {{CompatGeckoMobile("1")}} 6.0 6.0 1.0

Revision Source

<div>{{CSSRef}}</div>

<h2 id="Summary" name="Summary">Summary</h2>

<p><img alt="The effect of the CSS margin-top property on the element box" src="/files/4101/margin-top.svg" style="border-style:solid; border-width:1px; float:left; margin-bottom:2em; margin-right:1em" /><span class="seoSummary">The <strong><code>margin-top</code></strong> CSS property of an element sets the margin space required on the top of an element. A negative value is also allowed.</span></p>

<p><span class="seoSummary">This property has no effect on <em>non-replaced</em> inline elements, like {{HTMLElement("tt")}} or {{HTMLElement("span")}}.</span></p>

<p>{{cssinfo}}</p>

<h2 id="Syntax" name="Syntax">Syntax</h2>

<pre class="brush:css">
/* &lt;length&gt; values */
margin-top: 10px;        /* An absolute length */
margin-top: 1em;         /* A length relative to the text size */
margin-top: 5%;          /* A margin relative to the nearest block container's width */

/* Keyword values */
margin-top: auto;

/* Global values */
margin-top: inherit;
margin-top: initial;
margin-top: unset;
</pre>

<h3 id="Values" name="Values">Values</h3>

<dl>
 <dt><code>&lt;length&gt;</code></dt>
 <dd>Specifies a fixed width. See {{cssxref("&lt;length&gt;")}} for possible values.</dd>
 <dt><code>&lt;percentage&gt;</code></dt>
 <dd>A {{cssxref("&lt;percentage&gt;")}} always relative to the <strong>width</strong> of the containing block.</dd>
 <dt><code>auto</code></dt>
 <dd>See {{cssxref("margin")}}.</dd>
</dl>

<h3 id="Formal_syntax">Formal syntax</h3>

<pre class="syntaxbox">
{{csssyntax}}</pre>

<h2 id="Examples" name="Examples">Examples</h2>

<pre class="brush:css;">
.content { margin-top:   5%; }
.sidebox { margin-top: 10px; }
.logo    { margin-top: -5px; }
#footer  { margin-top:  1em; } 
</pre>

<h2 id="Specifications" name="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('CSS3 Box', '#the-margin', 'margin-top')}}</td>
   <td>{{Spec2('CSS3 Box')}}</td>
   <td>No significant change</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS3 Transitions', '#animatable-css', 'margin-top')}}</td>
   <td>{{Spec2('CSS3 Transitions')}}</td>
   <td>Defines <code>margin-top</code> as animatable.</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS2.1', 'box.html#margin-properties', 'margin-top')}}</td>
   <td>{{Spec2('CSS2.1')}}</td>
   <td>Removes its effect on inline elements.</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS1', '#margin-top', 'margin-top')}}</td>
   <td>{{Spec2('CSS1')}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_Compatibility" 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 support</td>
   <td>1.0</td>
   <td>{{CompatGeckoDesktop("1")}}</td>
   <td>3.0</td>
   <td>3.5</td>
   <td>1.0 (85)</td>
  </tr>
  <tr>
   <td><code>auto</code> value</td>
   <td>1.0</td>
   <td>{{CompatGeckoDesktop("1")}}</td>
   <td>6.0 (strict mode)</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>1.0</td>
   <td>{{CompatGeckoMobile("1")}}</td>
   <td>6.0</td>
   <td>6.0</td>
   <td>1.0</td>
  </tr>
 </tbody>
</table>
</div>
Revert to this revision