Open In App

How to Center Text in HTML?

Last Updated : 06 Nov, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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.

HTML
<center>
    <h1>GeeksforGeeks</h1>
    <p>This text is centered using the &lt;center&gt; tag.</p>
</center>

Output

centerText
center tag

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>).

HTML
<div style="text-align: center;">
    <h1>GeeksforGeeks</h1>
    <p>This text is centered using text-align.</p>
</div>

Output

textAlignCenter
text-align center

Related Article: How to center text in CSS ?


Similar Reads