---
title: text-indent
slug: Web/CSS/text-indent
translation_of: Web/CSS/text-indent
---
<div>{{CSSRef}}</div>

<p><code>text-indent</code> 属性能定义一个块元素首行文本内容之前的缩进量。</p>

<div>{{EmbedInteractiveExample("pages/css/text-indent.html")}}</div>

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

<pre><code>/* &lt;length&gt; 长度值 */
text-indent: 3mm;
text-indent: 40px;

/* &lt;percentage&gt;百分比值取决于其包含块(containing block)的宽度*/
text-indent: 15%;

/* 关键字 */
text-indent: 5em each-line;
text-indent: 5em hanging;
text-indent: 5em hanging each-line;

/* 全局值 */
text-indent: inherit;
text-indent: initial;
text-indent: unset;</code></pre>

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

<dl>
 <dt><code>&lt;length&gt;</code></dt>
 <dd><code>使用固定的&lt;length&gt;值来指定文本的缩进。允许使用负值。查阅可能</code>的 {{cssxref("&lt;length&gt;")}} 单位。</dd>
 <dt><code>&lt;percentage&gt;</code></dt>
 <dd>使用包含块宽度的百分比作为缩进.</dd>
 <dt><code>each-line</code> {{experimental_inline}}</dt>
 <dd>文本缩进会影响第一行,以及使用&lt;br&gt;强制断行后的第一行。</dd>
 <dt><code>hanging</code> {{experimental_inline}}</dt>
 <dd>该值会对所有的行进行反转缩进:除了第一行之外的所有的行都会被缩进,看起来就像第一行设置了一个负的缩进值。</dd>
</dl>

<h3 id="正式语法">正式语法</h3>

<dl>
 <dt>
 {{csssyntax}}
 </dt>
</dl>

<h2 id="例子">例子</h2>

<h3 id="HTML">HTML</h3>

<pre class="brush: html"><code>&lt;p&gt;Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy
    nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.&lt;/p&gt;</code></pre>

<h3 id="CSS">CSS</h3>

<pre class="brush: css"><code>p {
  text-indent: 5em;
  background: powderblue;
}</code>
</pre>

<h3 id="结果">结果</h3>

<p>{{EmbedLiveSample('例子')}}</p>

<h2 id="规范">规范</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></td>
  </tr>
 </tbody>
</table>

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

<h2 id="浏览器兼容性">浏览器兼容性</h2>

<p>{{Compat("css.properties.text-indent")}}</p>

<div id="compat-mobile"></div>