text-indent

  • Revision slug: CSS/text-indent
  • Revision title: text-indent
  • Revision id: 37554
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment 8 words added

Revision Content

{{ CSSRef() }}

Summary

The text-indent CSS property specifies how much horizontal space should be left before the beginning of the first line of the text content of an element. Horizontal spacing is with respect to the left (or right, for right-to-left layout) edge of the containing block element's box.

 

<style type="text/css"></style>
  • Initial value : 0
  • Applies to: block and inline-block elements, table cells
  • Inherited : yes
  • Percentages : refer to width of containing block
  • Media: visual
  • Computed value : the percentage as specified or the absolute length

Syntax

text-indent:  <length> | <percentage> && [ hanging || each-line ]

Values

<length>
Indentation is specified as fixed {{ Xref_csslength() }}. Negative Values are allowed. See {{ Xref_csslength() }} values for possible units.
<percentage>
Indentation is a {{ Xref_csspercentage() }} of the containing block width.
hanging {{ experimental_inline() }}
Indentation of the first line of the block container and each line following a forced line break, but not lines that wrap normally
each-line {{ experimental_inline() }}

Inverts which lines are indented

Examples

p { text-indent: 2em } 

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.

Specifications

Specification Status Comment
CSS Text Level 3 {{ Spec2('CSS3 Text') }} Added the hanging and each-line keywords
CSS 2.1 {{ Spec2('CSS2.1') }} The behavior with display: inline-block and anonymous block box has been explicitly defined.
CSS 1 {{ Spec2('CSS1') }}  

Browser compatibility

{{ CompatibilityTable() }}

Feature Firefox (Gecko) Chrome Internet Explorer Opera Safari
Basic support {{ CompatGeckoDesktop("1.0") }} 1.0 3.0 3.5 1.0 (85)
hanging {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }}
each-line {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }}
Feature Firefox Mobile (Gecko) Android IE Phone Opera Mobile Safari Mobile
Basic support {{ CompatGeckoMobile("1.9.2") }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}
hanging {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }}
each-line {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }}

See also

{{ CSS_Reference:Text() }}

{{ languages( { "fr": "fr/CSS/text-indent"} ) }}

Revision Source

<p>{{ CSSRef() }}</p>
<h2>Summary</h2>
<p>The<code> text-indent </code>CSS property specifies how much horizontal space should be left before the beginning of the first line of the text content of an element. Horizontal spacing is with respect to the left (or right, for right-to-left layout) edge of the containing block element's box.</p>
<p>  </p><style type="text/css"><![CDATA[.cssprop {
  display:table;
  padding: 0.4em;
  border-left:0.15em solid;
  background-color:#eeeeff
}
.cssprop li {
 display:table-row;
 padding: 3px;
 margin:0;
}
.cssprop li dfn {
  display:table-cell;
  padding: 0 5px;
  border-bottom: none;
  cursor:inherit;
}

	]]></style> <ul class="cssprop"> <li><dfn><span class="lang lang-en"><a href="/en/CSS/initial_value" rel="internal" title="en/CSS/initial_value">Initial value</a> </span>:</dfn> <code>0</code></li> <li><dfn>Applies to:</dfn> block and inline-block elements, table cells</li> <li><dfn><span class="lang lang-en"><a href="/en/CSS/inheritance" rel="internal" title="en/CSS/inheritance">Inherited</a> </span>:</dfn> yes</li> <li><dfn><span class="lang lang-en">Percentages </span>:</dfn> refer to width of containing block</li> <li><dfn>Media:</dfn> <span class="lang lang-en"><code><a href="/en/CSS/Media/Visual" rel="custom">visual</a></code> </span></li> <li><dfn><span class="lang lang-en"><a href="/en/CSS/computed_value" rel="internal" title="en/CSS/computed_value">Computed value</a> </span>:</dfn> the percentage as specified or the absolute length</li>
</ul><h2>Syntax</h2>
<pre>text-indent:  &lt;length&gt; | &lt;percentage&gt; &amp;&amp; [ hanging || each-line ]
</pre>
<h3>Values</h3>
<dl> <dt>&lt;length&gt;</dt> <dd>Indentation is specified as fixed {{ Xref_csslength() }}. Negative Values are allowed. See {{ Xref_csslength() }} values for possible units.</dd> <dt>&lt;percentage&gt;</dt> <dd>Indentation is a {{ Xref_csspercentage() }} of the containing block width.</dd> <dt><code>hanging</code> {{ experimental_inline() }}</dt> <dd>Indentation of the first line of the block container and each line following a forced line break, but not lines that wrap normally</dd> <dt><code>each-line</code> {{ experimental_inline() }}</dt> <br> <dd>Inverts which lines are indented</dd>
</dl><h2>Examples</h2>
<pre>p { text-indent: 2em } 
</pre>
<p style="text-indent:2em; max-width:40em; background:gold">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
<h2>Specifications</h2>
<table class="standard-table"> <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://dev.w3.org/csswg/css3-text/#text-indent" title="http://dev.w3.org/csswg/css3-text/#text-indent">CSS Text Level 3</a></td> <td>{{ Spec2('CSS3 Text') }}</td> <td>Added the <code>hanging</code> and <code>each-line</code> keywords</td> </tr> <tr> <td><a class="external" href="http://www.w3.org/TR/CSS21/text.html#indentation-prop" title="http://www.w3.org/TR/CSS21/text.html#indentation-prop">CSS 2.1</a></td> <td>{{ Spec2('CSS2.1') }}</td> <td>The behavior with <code>display: inline-block</code> and anonymous block box has been explicitly defined.</td> </tr> <tr> <td><a class=" external" href="http://www.w3.org/TR/REC-CSS1/#text-indent" title="http://www.w3.org/TR/REC-CSS1/#text-indent">CSS 1</a></td> <td>{{ Spec2('CSS1') }}</td> <td> </td> </tr> </tbody>
</table>
<h2>Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Firefox (Gecko)</th> <th>Chrome</th> <th>Internet Explorer</th> <th>Opera</th> <th>Safari</th> </tr> <tr> <td>Basic support</td> <td>{{ CompatGeckoDesktop("1.0") }}</td> <td>1.0</td> <td>3.0</td> <td>3.5</td> <td>1.0 (85)</td> </tr> <tr> <td><code>hanging</code></td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> </tr> <tr> <td><code>each-line</code></td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> </tr> </tbody> </table>
</div>
<div id="compat-mobile"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Firefox Mobile (Gecko)</th> <th>Android</th> <th>IE Phone</th> <th>Opera Mobile</th> <th>Safari Mobile</th> </tr> <tr> <td>Basic support</td> <td>{{ CompatGeckoMobile("1.9.2") }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> </tr> <tr> <td><code>hanging</code></td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> </tr> <tr> <td><code>each-line</code></td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> </tr> </tbody> </table>
</div>
<h2>See also</h2>
<p>{{ CSS_Reference:Text() }}</p>
<p>{{ languages( { "fr": "fr/CSS/text-indent"} ) }}</p>
Revert to this revision