HTML <center> Element

The <center> element was historically used to horizontally center text, images, tables, and other content within a webpage. It was widely used before CSS became the standard way to control the alignment and layout of HTML content.

Historical Syntax

Older HTML documents may contain markup similar to the following:

<center>
  <h2>Welcome to My Website</h2>
  <p>This content is centered on the page.</p>
</center>

In supporting browsers, the contents of the <center> element were horizontally centered. This code is shown for historical reference only and should not be used in modern HTML.

Attributes

The <center> element did not have any element-specific attributes. Its purpose was simply to apply centered alignment to the content contained within it.

Historical Use

The <center> element provided authors with a simple way to center webpage content before CSS was widely available. It could contain text as well as block-level content, making it convenient for centering headings, paragraphs, images, tables, and groups of elements.

Because the element was so simple to use, it became extremely common on websites during the 1990s. Pages frequently contained multiple <center> elements solely to control visual layout rather than to describe the meaning or structure of the content.

Why It Became Obsolete

The <center> element controls presentation rather than describing what its content means. As CSS became the standard method for controlling webpage presentation, alignment no longer needed to be represented by a dedicated HTML element.

CSS also provides much greater control. Text can be centered independently from block elements, and modern layout systems such as Flexbox and Grid can center content horizontally, vertically, or in both directions. The <center> element was deprecated in HTML 4 and is obsolete in modern HTML.

Modern Alternative

There is no single CSS rule that replaces every historical use of <center>. The correct method depends on what is being centered.

For text and inline content, use the CSS text-align property:

<div class="center-text">
  <h2>Welcome to My Website</h2>
  <p>This content is centered on the page.</p>
</div>
.center-text {
  text-align: center;
}

A block element with a defined width can be centered horizontally by using automatic left and right margins:

.center-block {
  width: 300px;
  margin-left: auto;
  margin-right: auto;
}
Play in Editor

Legacy Browser Support

Modern browsers generally continue to recognize the <center> element and center its contents for compatibility with older webpages. This extensive legacy support is one reason old websites containing <center> markup may still appear much as they originally did.

Browser support does not make the element valid modern HTML. Existing <center> elements should be replaced with appropriate HTML and CSS when older webpages are updated.

For detailed legacy browser compatibility information, see Can I Use: HTML <center> Element .

The <center> element has no direct modern HTML replacement because centering is a presentation decision rather than a type of content. Use an appropriate structural element such as <div> when a container is needed, and use CSS to control its alignment and layout.

Specifications

The <center> element is listed as an entirely obsolete, non-conforming feature in the WHATWG HTML Living Standard . Authors should use CSS to control alignment instead.