HTML use the CSS text-align
property in order to align different contents like div, label, etc. The alignment is done for the content inside the specified item in which the text-align property is used.

text-align Syntax
The text-align has the following simple syntax.
style="text-align:ALIGN"
- ALIGN is the alignment side like
left
,rigth
,center
justify
,initial
andinherit
.
Align Text To Center
The text-align:center
can be used to center align text in an element.
<h1 style="text-align:center;">Centered Heading</h1>
<p style="text-align:center;">Centered Paragraph.</p>
Align Text To Right
The text-align:right
can be used to right-align text in an element.
<h1 style="text-align:right;">Right Aligned Heading</h1>
<p style="text-align:right;">Right Aligned Paragraph.</p>
Align Text To Left
The default text alignment for text in HTML is left. But the alignment can be changed globally and we may need to set the alignment as left again. The text-align:left
can be used to right-align text in an element.
<h1 style="text-align:left;">Left Aligned Heading</h1>
<p style="text-align:left;">Left Aligned Paragraph.</p>
Align Text As Justified
The text can be justified and lines are stretched where each line has equal width.
<h1 style="text-align:justify;">Justified Heading</h1>
<p style="text-align:justify;">Justified Paragraph.</p>
Align Text According To Parent
The text alignment configuration can be inherited from a parent by using text-align:inherit
.
<h1 style="text-align:inherited;">Heading</h1>
<p style="text-align:inherited;">Paragraph.</p>