totn HTML

HTML: <center> tag

This HTML tutorial explains how to use the HTML element called the <center> tag with syntax and examples.

Description

The HTML <center> tag is used to center the text horizontally in the HTML document. Since this tag was removed in HTML5, it is recommended that you use the CSS text-align property to format the text horizontally in the document. This tag is also commonly referred to as the <center> element.

WARNING: The <center> tag has been removed in HTML5. Use CSS instead such as the text-align property.

Syntax

In HTML, the syntax for the <center> tag is:

<body>
<center>
  <p>Your centered text goes here</p>
</center>
</body>

Sample Output


Attributes

Only the Global Attributes apply to the <center> tag. There are no attributes that are specific to the <center> tag.

Note

  • The HTML <center> element is found within the <body> tag.
  • The <center> tag is obsolete in HTML5. Use the CSS text-align property instead to format the horizontal alignment of the text.

Browser Compatibility

The <center> tag has basic support with the following browsers:

  • Chrome
  • Android
  • Firefox (Gecko)
  • Firefox Mobile (Gecko)
  • Internet Explorer (IE)
  • Edge Mobile
  • Opera
  • Opera Mobile
  • Safari (WebKit)
  • Safari Mobile

Example

We will discuss the <center> tag below, exploring examples of how to use the <center> tag in HTML5, HTML 4.01 Transitional, XHTML 1.0 Transitional, XHTML 1.0 Strict, and XHTML 1.1.