files/en-us/web/css/reference/properties/text-align/index.md
The text-align CSS property sets the horizontal alignment of the inline-level content inside a block element or table-cell box. This means it works like {{cssxref("vertical-align")}} but in the horizontal direction.
{{InteractiveExample("CSS Demo: text-align")}}
text-align: start;
text-align: end;
text-align: center;
text-align: justify;
<section id="default-example">
<div id="example-element">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
est laborum.
</p>
</div>
</section>
section {
font-size: 1.5em;
}
#default-example > div {
width: 250px;
}
/* Keyword values */
text-align: start;
text-align: end;
text-align: left;
text-align: right;
text-align: center;
text-align: justify;
text-align: match-parent;
/* Block alignment values (Non-standard syntax) */
text-align: -moz-center;
text-align: -webkit-center;
/* Global values */
text-align: inherit;
text-align: initial;
text-align: revert;
text-align: revert-layer;
text-align: unset;
The text-align property is specified as a single keyword from the list below.
start
left if direction is left-to-right and right if direction is right-to-left.end
right if direction is left-to-right and left if direction is right-to-left.left
right
center
justify
match-parent
inherit, but the values start and end are calculated according to the parent's {{cssxref("direction")}} and are replaced by the appropriate left or right value.The inconsistent spacing between words created by justified text can be problematic for people with cognitive concerns such as Dyslexia.
{{CSSInfo}}
{{csssyntax}}
<p class="example">
Integer elementum massa at nulla placerat varius. Suspendisse in libero risus,
in interdum massa. Vestibulum ac leo vitae metus faucibus gravida ac in neque.
Nullam est eros, suscipit sed dictum quis, accumsan a ligula.
</p>
.example {
text-align: start;
border: solid;
}
{{EmbedLiveSample("Start_alignment","100%","100%")}}
<p class="example">
Integer elementum massa at nulla placerat varius. Suspendisse in libero risus,
in interdum massa. Vestibulum ac leo vitae metus faucibus gravida ac in neque.
Nullam est eros, suscipit sed dictum quis, accumsan a ligula.
</p>
.example {
text-align: center;
border: solid;
}
{{EmbedLiveSample("Centered_text", "100%", "100%")}}
<p class="example">
Integer elementum massa at nulla placerat varius. Suspendisse in libero risus,
in interdum massa. Vestibulum ac leo vitae metus faucibus gravida ac in neque.
Nullam est eros, suscipit sed dictum quis, accumsan a ligula.
</p>
.example {
text-align: justify;
border: solid;
}
{{EmbedLiveSample('Example using "justify"',"100%","100%")}}
This example demonstrates the use of text-align on {{htmlelement("table")}} elements:
text-align: left set on the {{htmlelement("thead")}}, while the third is set to right-aligned.<table>
<caption>
Example table
</caption>
<thead>
<tr>
<th>Col 1</th>
<th>Col 2</th>
<th class="right">Col 3</th>
</tr>
</thead>
<tbody>
<tr class="right">
<td>11</td>
<td class="center">12</td>
<td>13</td>
</tr>
<tr class="center">
<td>21</td>
<td>22</td>
<td>23</td>
</tr>
<tr id="r3">
<td class="right">31</td>
<td>32</td>
<td>33</td>
</tr>
</tbody>
</table>
table {
border-collapse: collapse;
border: solid black 1px;
width: 250px;
height: 150px;
}
thead {
text-align: left;
}
td,
th {
border: solid 1px black;
}
.center {
text-align: center;
}
.right,
caption {
text-align: right;
}
{{EmbedLiveSample('Table alignment', "100%", "200")}}
{{Specifications}}
{{Compat}}