We can use the following two methods to center a text in HTML:
Let's look at a few examples.
To center a text, we can enclose it between the
<center> <p>This text is in center.</p> </center>
<center></center>tag to wrap the
<p>tag and center the text.
<center></center>tag was deprecated in HTML 4 and is no longer recommended to be used. Some browsers may still support this tag. However, it can stop working at any moment.
To center a text using CSS, we can add the
text-align:center property to the element to be centered.
<p style="text-align:center"> This text is in center. </p>
<p>tag and added the
text-align:centerproperty to it to center it.
View all Courses