Description
The HTML element <center>
is used to center align the contents enclosed within the element.
This element is not supported in HTML5 and you should avoid using it in the markup. Instead, use CSS properties.
The below table summarizes its usage.
Usage Details | |
Placement | It is displayed as a Block element. |
Contents | It can contain Block elements, Inline elements, and text. |
Tags | Both the opening and closing tags are required. |
Versions | HTML 3.2, 4, 4.01 This element is deprecated in HTML 4.01 and obsolete since HTML5, so avoid using this element in your markup. Instead, use the CSS properties. |
Syntax
Here is the basic syntax of the <center>
element.
<center>...</center>
Examples
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example - HTML Element center</title>
</head>
<body>
<!-- The center element is obsolete and not valid in HTML5, so avoid using it in your markup -->
<center><p>This paragraph is center aligned using an element.</p></center>
<!-- Alternative and better way to align the content is using CSS properties as shown below. -->
<p style="text-align: center;">This paragraph is also center aligned but using CSS properties.</p>
</body>
</html>
Attributes
The following table shows the list of supported and unsupported attributes for the <center>
element.
Attribute Type | Details |
Element-Specific Attributes | The tag <center> doesn't have any element-specific attributes. |
Global Attributes | Like all other HTML tags, the tag <center> supports the HTML Global Attributes. |
Event Attributes | The tag <center> also supports the HTML Event Attributes. |
Browser Compatibility
The tag <center>
is supported in all modern browsers.
- Google Chrome 1+
- Internet Explorer or Edge 2+
- Firefox 1+
- Apple Safari 1+
- Opera 4+
Related Links
- HTML Elements
- HTML Attributes
- HTML Text Formatting
- CSS Alignment