How to Center Text in HTML?
Last Updated :
06 Nov, 2024
Improve
To center text in HTML, we can use CSS text-align: center property. It aligns the text to center horizontally. The <center> tag was used in older versions to center the text horizontally, but it is depreciated in HTML 5.
Center Text using center Tag
The <center> tag is a block-level element that is used to center text horizontally within its container element.
<center>
<h1>GeeksforGeeks</h1>
<p>This text is centered using the <center> tag.</p>
</center>
Output
Note: The <center> tag is depricated from HTML 5, so we will use CSS text-align property to center the text.
Center Text using text-align Property
The text-align property is the simplest way to horizontally center the text. It is suitable for both inline and block-level elements like paragraphs (<p>), headings (<h1> to <h6>), and divs (<div>).
<div style="text-align: center;">
<h1>GeeksforGeeks</h1>
<p>This text is centered using text-align.</p>
</div>
Output
Related Article: How to center text in CSS ?