-
Notifications
You must be signed in to change notification settings - Fork 22.7k
/
Copy pathindex.md
260 lines (199 loc) · 6.69 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
---
title: text-indent
slug: Web/CSS/text-indent
page-type: css-property
browser-compat: css.properties.text-indent
---
{{CSSRef}}
The **`text-indent`** [CSS](/en-US/docs/Web/CSS) property sets the length of empty space (indentation) that is put before lines of text in a block.
{{InteractiveExample("CSS Demo: text-indent")}}
```css interactive-example-choice
text-indent: 0;
```
```css interactive-example-choice
text-indent: 30%;
```
```css interactive-example-choice
text-indent: -3em;
```
```css interactive-example-choice
text-indent: 3em each-line;
```
```css interactive-example-choice
text-indent: 3em hanging;
```
```css interactive-example-choice
text-indent: 3em hanging each-line;
```
```html interactive-example
<section id="default-example">
<div id="example-element">
<p>
This text is contained within a single paragraph. This paragraph is two
sentences long.
</p>
<p>
This is a new paragraph. There is a line break element
<code><br></code> after this sentence.<br />There it is! Notice how
it affects the indentation.
</p>
</div>
</section>
```
```css interactive-example
section {
font-size: 1.25em;
background-color: #483d8b;
align-items: start;
}
#example-element {
text-align: left;
margin: 0 0 0 3em;
background-color: #6a5acd;
color: white;
}
```
Horizontal spacing is with respect to the left (or right, for right-to-left layout) edge of the containing block-level element's content box.
## Syntax
```css
/* <length> values */
text-indent: 3mm;
text-indent: 40px;
/* <percentage> value
relative to the containing block width */
text-indent: 15%;
/* Keyword values */
text-indent: 5em each-line;
text-indent: 5em hanging;
text-indent: 5em hanging each-line;
/* Global values */
text-indent: inherit;
text-indent: initial;
text-indent: revert;
text-indent: revert-layer;
text-indent: unset;
```
### Values
- {{cssxref("<length>")}}
- : Indentation is specified as an absolute {{cssxref("<length>")}}. Negative values are allowed. See {{cssxref("<length>")}} values for possible units.
- {{cssxref("<percentage>")}}
- : Indentation is a {{cssxref("<percentage>")}} of the containing block's width.
- `each-line`
- : 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`
- : Inverts which lines are indented. All lines _except_ the first line will be indented.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Basic indent
#### HTML
```html
<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy
nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
</p>
<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy
nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
</p>
```
#### CSS
```css
p {
text-indent: 5em;
background: powderblue;
}
```
#### Result
{{ EmbedLiveSample('Basic_indent','100%','100%') }}
### Skipping indentation on the first paragraph
A common typographic practice when paragraph indentation is present is to skip the indentation for the first paragraph. As _The Chicago Manual of Style_ puts it, "the first line of text following a subhead may begin flush left or be indented by the usual paragraph indention."
Treating first paragraphs differently from subsequent paragraphs can be done using the [next-sibling combinator](/en-US/docs/Web/CSS/Next-sibling_combinator), as in the following example:
#### HTML
```html
<h2>Lorem ipsum</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse eu
venenatis quam. Vivamus euismod eleifend metus vitae pharetra. In vel tempor
metus. Donec dapibus feugiat euismod. Vivamus interdum tellus dolor. Vivamus
blandit eros et imperdiet auctor. Mauris sapien nunc, condimentum a efficitur
non, elementum ac sapien. Cras consequat turpis non augue ullamcorper, sit
amet porttitor dui interdum.
</p>
<p>
Sed laoreet luctus erat at rutrum. Proin velit metus, luctus in sapien in,
tincidunt mattis ex. Praesent venenatis orci at sagittis eleifend. Nulla
facilisi. In feugiat vehicula magna iaculis vehicula. Nulla suscipit tempor
odio a semper. Donec vitae dapibus ipsum. Donec libero purus, convallis eu
efficitur id, pulvinar elementum diam. Maecenas mollis blandit placerat. Ut
gravida pellentesque nunc, in eleifend ante convallis sit amet.
</p>
<h2>Donec ullamcorper elit nisl</h2>
<p>
Donec ullamcorper elit nisl, sagittis bibendum massa gravida in. Fusce tempor
in ante gravida iaculis. Integer posuere tempor metus. Vestibulum lacinia,
nunc et dictum viverra, urna massa aliquam tellus, id mollis sem velit
vestibulum nulla. Pellentesque habitant morbi tristique senectus et netus et
malesuada fames ac turpis egestas. Donec vulputate leo ut iaculis ultrices.
Cras egestas rhoncus lorem. Nunc blandit tempus lectus, rutrum hendrerit orci
eleifend id. Ut at quam velit.
</p>
<p>
Aenean rutrum tempor ligula, at luctus ligula auctor vestibulum. Sed
sollicitudin velit in leo fringilla sollicitudin. Proin eu gravida arcu. Nam
iaculis malesuada massa, eget aliquet turpis sagittis sed. Sed mollis tellus
ac dui ullamcorper, nec lobortis diam pellentesque. Quisque dapibus accumsan
libero, sed euismod ipsum ullamcorper sed.
</p>
```
#### CSS
```css
p {
text-align: justify;
margin: 1em 0 0 0;
}
p + p {
text-indent: 2em;
margin: 0;
}
```
#### Result
{{ EmbedLiveSample('Skipping_indentation_on_the_first_paragraph','','500px') }}
### Percentage indent
#### HTML
```html
<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy
nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
</p>
<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy
nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
</p>
```
#### CSS
```css
p {
text-indent: 30%;
background: plum;
}
```
#### Result
{{ EmbedLiveSample('Percentage_indent','100%','100%') }}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Learn to style HTML using CSS](/en-US/docs/Learn_web_development/Core/Styling_basics)
- Related CSS properties:
- [`text-justify`](/en-US/docs/Web/CSS/text-justify)
- [`text-orientation`](/en-US/docs/Web/CSS/text-orientation)
- [`text-overflow`](/en-US/docs/Web/CSS/text-overflow)
- [`text-rendering`](/en-US/docs/Web/CSS/text-rendering)
- [`text-transform`](/en-US/docs/Web/CSS/text-transform)
- {{cssxref('hanging-punctuation')}}
- [CSS Text Decoration](/en-US/docs/Web/CSS/CSS_text_decoration) CSS module
- [CSS Text module](/en-US/docs/Web/CSS/CSS_text)