How to center text in HTML?

The text in an HTML document can be horizontally centred by using the <centre> HTML tag. Since HTML5 did away with this tag, it is advised that you format the document's text horizontally instead by using the CSS text-align property. The <centre> element is another name for this tag.

Note − Not supported in HTML5


<p><center> ... </center></p>

Following are the examples…


In the following example we are using <center> tag to make our text aligned to the center.

<!DOCTYPE html> <html> <body> <p><center>Welcome to TutorialsPoint</center></p> <p>The Best E-Way learning.</p> </body> </html>


On executing the above script, the text "welcome to tutorialspoint" will get displayed at the centre of our webpage.

Example: Using CSS

In the following example we are using css style (text-align:center) to make our text display at center.

<!DOCTYPE html> <html> <style> h1 {text-align: center;} p {text-align: center;} div {text-align: center;} </style> <body> <h1>TUTORIALSPOINT</h1> <p>The E-Way Learning.</p> <div>Welcome To Tutorials.</div> </body> </html>


When we run the above script, the text is displayed in the centre of our webpage, as specified by the CSS property text-align: center.

Updated on: 31-Aug-2023

111K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started