left

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

Revision Content

{{CSSRef}}

Summary

The left CSS property specifies part of the position of positioned elements.

For absolutely positioned elements (those with {{Cssxref("position")}}: absolute or position: fixed), it specifies the distance between the left margin edge of the element and the left edge of its containing block.

{{cssbox("left")}}

Syntax

Formal syntax: {{csssyntax("left")}}
left: 3px         /* <length> values */
left: 2.4em

left: 10%         /* <percentages> of the width of the containing block */

left: auto

left: inherit

Values

<length>
Is a negative, null, or positive {{xref_csslength}} that represents:
  • for absolutely positioned elements, the distance to the left edge of the containing block
  • for relatively positioned elements, the offset that the element is moved left from its position in the normal flow if it wasn't positioned.
<percentage>
Is a {{xref_csspercentage}} of the containing block's width, used as described in the summary.
auto
Is a keyword that represents:
  • for absolutely positioned elements, the position of the element based on the {{Cssxref("right")}} property and treat width: auto as a width based on the content.
  • for relatively positioned elements, the left offset of the element from its original position based on the {{Cssxref("right")}} property, or if right is also auto, do not offset it at all.
inherit
Is a keyword indicating that the value is the same as the computed value from its parent element (which may not be its containing block). This computed value is then handled like it was a {{xref_csslength}}, {{xref_csspercentage}} or the auto keyword.

Examples

CSS Content

#wrap {
  width: 700px;
  margin: 0 auto;
  background: #5C5C5C;
}

pre {
  white-space: pre;
  white-space: pre-wrap;
  white-space: pre-line;
  word-wrap: break-word;
}

#example_1 {
  width: 200px;
  height: 200px;
  position: absolute;
  left: 20px;
  top: 20px;
  background-color: #D8F5FF;
}

#example_2 {
  width: 200px;
  height: 200px;
  position: relative;
  top: 0;
  right: 0;
  background-color: #C1FFDB;

}
#example_3 {
  width: 600px;
  height: 400px;
  position: relative;
  top: 20px;
  left: 20px;
  background-color: #FFD7C2;
}

#example_4 {
  width:200px;
  height:200px;
  position:absolute;
  bottom:10px;
  right:20px;
  background-color:#FFC7E4;
}

HTML Content

<div id="wrap">
  <div id="example_1">
    <pre>
      position: absolute;
      left: 20px;
      top: 20px;
    </pre>
    <p>The only containing element for this div is the main window, so it positions itself in relation to it.</p>
  </div>

  <div id="example_2">
    <pre>
      position: relative;
      top: 0;
      right: 0;
    </pre>
    <p>Relative position in relation to its siblings.</p>
  </div>

  <div id="example_3">
    <pre>
      float: right;
      position: relative;
      top: 20px;
      left: 20px;
    </pre>
    <p>Relative to its sibling div above, but removed from flow of content.</p>

    <div id="example_4">
      <pre>
        position: absolute;
        top: 10px;
        left: 20px;
      </pre>
      <p>Absolute position inside of a parent with relative position</p>
    </div>
  </div>
</div>

Live sample

{{EmbedLiveSample('Examples',1200,650)}}

Specifications

Specification Status Comment
{{SpecName('CSS3 Transitions', '#animatable-css', 'left')}} {{Spec2('CSS3 Transitions')}} Defines left as animatable.
{{SpecName('CSS2.1', 'visuren.html#propdef-left', 'left')}} {{Spec2('CSS2.1')}}  

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 {{CompatGeckoDesktop("1")}} 5.5 5.0 1.0
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support 1.0 {{CompatGeckoMobile("1")}} 6.0 6.0 1.0

See also

  • {{CSS_Reference:Position}}

Revision Source

<div>
  {{CSSRef}}</div>
<h2 id="Summary" name="Summary">Summary</h2>
<p>The <code>left</code> CSS property specifies part of the position of positioned elements.</p>
<p>For absolutely positioned elements (those with {{Cssxref("position")}}<code>: absolute</code> or <code>position: fixed</code>), it specifies the distance between the left margin edge of the element and the left edge of its containing block.</p>
<p>{{cssbox("left")}}</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="twopartsyntaxbox">
<a href="/en-US/docs/CSS/Value_definition_syntax" title="CSS/Value_definition_syntax">Formal syntax</a>: {{csssyntax("left")}}
</pre>
<pre>
left: 3px         /* &lt;length&gt; values */
left: 2.4em

left: 10%         /* &lt;percentages&gt; of the width of the containing block */

left: auto

left: inherit
</pre>
<h3 id="Values" name="Values">Values</h3>
<dl>
  <dt>
    <code>&lt;length&gt;</code></dt>
  <dd>
    Is a negative, null, or positive {{xref_csslength}} that represents:
    <ul>
      <li>for <em>absolutely positioned elements</em>, the distance to the left edge of the containing block</li>
      <li>for <em>relatively positioned elements</em>, the offset that the element is moved left from its position in the normal flow if it wasn't positioned.</li>
    </ul>
  </dd>
  <dt>
    <code>&lt;percentage&gt;</code></dt>
  <dd>
    Is a {{xref_csspercentage}} of the containing block's width, used as described in the <a href="#Summary">summary</a>.</dd>
  <dt>
    <code>auto</code></dt>
  <dd>
    Is a keyword that represents:
    <ul>
      <li>for absolutely positioned elements, the position of the element based on the {{Cssxref("right")}} property and treat <code>width: auto</code> as a width based on the content.</li>
      <li>for relatively positioned elements, the left offset of the element from its original position based on the {{Cssxref("right")}} property, or if <code>right</code> is also <code>auto</code>, do not offset it at all.</li>
    </ul>
  </dd>
  <dt>
    <code>inherit</code></dt>
  <dd>
    Is a keyword indicating that the value is the same as the computed value from its parent element (which may not be its containing block). This computed value is then handled like it was a {{xref_csslength}}, {{xref_csspercentage}} or the <code>auto</code> keyword.</dd>
</dl>
<h2 id="Examples" name="Examples">Examples</h2>
<h3 id="CSS_Content">CSS Content</h3>
<pre class="brush: css">
#wrap {
  width: 700px;
  margin: 0 auto;
  background: #5C5C5C;
}

pre {
  white-space: pre;
  white-space: pre-wrap;
  white-space: pre-line;
  word-wrap: break-word;
}

#example_1 {
  width: 200px;
  height: 200px;
  position: absolute;
  left: 20px;
  top: 20px;
  background-color: #D8F5FF;
}

#example_2 {
  width: 200px;
  height: 200px;
  position: relative;
  top: 0;
  right: 0;
  background-color: #C1FFDB;

}
#example_3 {
  width: 600px;
  height: 400px;
  position: relative;
  top: 20px;
  left: 20px;
  background-color: #FFD7C2;
}

#example_4 {
  width:200px;
  height:200px;
  position:absolute;
  bottom:10px;
  right:20px;
  background-color:#FFC7E4;
}</pre>
<h3 id="HTML_Content">HTML Content</h3>
<pre class="brush: html">
&lt;div id="wrap"&gt;
  &lt;div id="example_1"&gt;
    &lt;pre&gt;
      position: absolute;
      left: 20px;
      top: 20px;
    &lt;/pre&gt;
    &lt;p&gt;The only containing element for this div is the main window, so it positions itself in relation to it.&lt;/p&gt;
  &lt;/div&gt;

  &lt;div id="example_2"&gt;
    &lt;pre&gt;
      position: relative;
      top: 0;
      right: 0;
    &lt;/pre&gt;
    &lt;p&gt;Relative position in relation to its siblings.&lt;/p&gt;
  &lt;/div&gt;

  &lt;div id="example_3"&gt;
    &lt;pre&gt;
      float: right;
      position: relative;
      top: 20px;
      left: 20px;
    &lt;/pre&gt;
    &lt;p&gt;Relative to its sibling div above, but removed from flow of content.&lt;/p&gt;

    &lt;div id="example_4"&gt;
      &lt;pre&gt;
        position: absolute;
        top: 10px;
        left: 20px;
      &lt;/pre&gt;
      &lt;p&gt;Absolute position inside of a parent with relative position&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;</pre>
<h3 id="Live_sample">Live sample</h3>
<p>{{EmbedLiveSample('Examples',1200,650)}}</p>
<h2 id="Notes" name="Notes">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 Transitions', '#animatable-css', 'left')}}</td>
      <td>{{Spec2('CSS3 Transitions')}}</td>
      <td>Defines <code>left</code> as animatable.</td>
    </tr>
    <tr>
      <td>{{SpecName('CSS2.1', 'visuren.html#propdef-left', 'left')}}</td>
      <td>{{Spec2('CSS2.1')}}</td>
      <td>&nbsp;</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</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>1.0</td>
        <td>{{CompatGeckoDesktop("1")}}</td>
        <td>5.5</td>
        <td>5.0</td>
        <td>1.0</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>
<h2 id="See_also">See also</h2>
<ul>
  <li>{{CSS_Reference:Position}}</li>
</ul>
Revert to this revision