text-indent

  • Revision slug: Web/CSS/text-indent
  • Revision title: text-indent
  • Revision id: 394625
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment Moved From CSS/text-indent to Web/CSS/text-indent

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.

{{cssbox("text-indent")}}

Syntax

Formal syntax: {{csssyntax("text-indent")}}
text-indent: 3em       /* <length> values */
text-indent: 40px
text-indent: 15%       /* <percentage> values, relatives to the containing block width */
text-indent: each-line /* keywords values */
text-indent: hanging

text-indent: inherit
</percentage></length>

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.
each-line {{experimental_inline}}
Indentation affects the first line of the block container as well as each line after a forced line break, but does not affect lines after a soft wrap break.
hanging {{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
{{SpecName('CSS3 Text', '#text-indent', 'text-indent')}} {{Spec2('CSS3 Text')}} Added the hanging and each-line keywords
{{SpecName('CSS3 Transitions', '#animatable-css', 'text-indent')}} {{Spec2('CSS3 Transitions')}} Lists text-indent as animatable.
{{SpecName('CSS2.1', 'text.html#indentation-prop', 'text-indent')}} {{Spec2('CSS2.1')}} The behavior with display: inline-block and anonymous block boxes have been explicitly defined.
{{SpecName('CSS1', '#text-indent', 'text-indent')}} {{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}}

Revision Source

<div>
  {{CSSRef}}</div>
<h2 id="Summary">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>{{cssbox("text-indent")}}</p>
<h2 id="Syntax">Syntax</h2>
<pre class="twopartsyntaxbox">
<a href="/en-US/docs/CSS/Value_definition_syntax" title="CSS/Value_definition_syntax">Formal syntax</a>: {{csssyntax("text-indent")}}</pre>
<pre>
text-indent: 3em       /* <length> values */
text-indent: 40px
text-indent: 15%       /* <percentage> values, relatives to the containing block width */
text-indent: each-line /* keywords values */
text-indent: hanging

text-indent: inherit
</percentage></length></pre>
<h3 id="Values">Values</h3>
<dl>
  <dt>
    <code>&lt;length&gt;</code></dt>
  <dd>
    Indentation is specified as fixed {{Xref_csslength}}. Negative values are allowed. See {{Xref_csslength}} values for possible units.</dd>
  <dt>
    <code>&lt;percentage&gt;</code></dt>
  <dd>
    Indentation is a {{Xref_csspercentage}} of the containing block width.</dd>
  <dt>
    <code>each-line</code> {{experimental_inline}}</dt>
  <dd>
    Indentation affects the first line of the block container as well as each line after a <i>forced line break</i>, but does not affect lines after a <i>soft wrap break</i>.</dd>
  <dt>
    <code>hanging</code> {{experimental_inline}}</dt>
  <dd>
    Inverts which lines are indented</dd>
</dl>
<h2 id="Examples">Examples</h2>
<pre class="brush: css">
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 id="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 Text', '#text-indent', 'text-indent')}}</td>
      <td>{{Spec2('CSS3 Text')}}</td>
      <td>Added the <code>hanging</code> and <code>each-line</code> keywords</td>
    </tr>
    <tr>
      <td>{{SpecName('CSS3 Transitions', '#animatable-css', 'text-indent')}}</td>
      <td>{{Spec2('CSS3 Transitions')}}</td>
      <td>Lists <code>text-indent</code> as animatable.</td>
    </tr>
    <tr>
      <td>{{SpecName('CSS2.1', 'text.html#indentation-prop', 'text-indent')}}</td>
      <td>{{Spec2('CSS2.1')}}</td>
      <td>The behavior with <code>display: inline-block</code> and anonymous block boxes have been explicitly defined.</td>
    </tr>
    <tr>
      <td>{{SpecName('CSS1', '#text-indent', 'text-indent')}}</td>
      <td>{{Spec2('CSS1')}}</td>
      <td>&nbsp;</td>
    </tr>
  </tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<div>
  {{CompatibilityTable}}</div>
<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 id="See_also">See also</h2>
<ul>
  <li>{{CSS_Reference:Text}}</li>
</ul>
Revert to this revision