HTML <center> Tag

The <center> tag was used to align texts center.

This tag is a block-level element that can contain paragraphs and other block-level and inline elements.

This tag is usually included in the <body> element.

Note: The <center> tag is not used in HTML5.

Recommendation: Use the CSS text-align property instead.

Syntax

The <center> tag comes in pairs. The content must be written between opening (<center>) and closing (</center>) tags.

Example

<!DOCTYPE html>
<html>
   <body>
      <p>This is a left aligned text.</p>
      <center>This one is center-aligned text.</center>
      <p>One more left-aligned text here.</p>
   </body>
</html>

Let's see an example with the CSS text-align property which is used for aligning the inner content of a block element.

Example

<!DOCTYPE html>
<html>
   <body>
      <p>This text is left aligned text.</p>
      <p style="text-align:center">This one is center-aligned text.</p>
     <p style="text-align:right">And this one is right-aligned text.</p>
   </body>
</html>