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.
HTML5 Document
You can not use the <center> tag in HTML5. Instead, use the CSS text-align property to format the horizontal alignment of the text.
HTML 4.01 Transitional Document
If you created a new web page in HTML 4.01 Transitional, your <center> tag might look like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>HTML 4.01 Transitional Example by www.techonthenet.com</title>
</head>
<body>
<h1>Heading 1</h1>
<center>
<p>Your centered text goes here</p>
</center>
</body>
</html>
In this HTML 4.01 Transitional Document example, the text in the <p> tag would be centered horizontally.
XHTML 1.0 Transitional Document
If you created a new web page in XHTML 1.0 Transitional, your <center> tag might look like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>XHMTL 1.0 Transitional Example by www.techonthenet.com</title>
</head>
<body>
<h1>Heading 1</h1>
<center>
<p>Your centered text goes here</p>
</center>
</body>
</html>
In this XHTML 1.0 Transitional Document example, the text in the <p> tag would be centered horizontally.
XHTML 1.0 Strict Document
You can not use the <center> tag in XHTML 1.0 Strict.
XHTML 1.1 Document
You can not use the <center> tag in XHTML 1.1.