Path // www.yourhtmlsource.comReference → <center>

<center>


The <center> element was used to horizontally center its block-level contents. It was a purely presentational element that has been replaced by CSS text and layout alignment properties.

Clock This page was last updated on 2025-11-17



Deprecation Warning

This element is deprecated and should not be used. The <center> element was deprecated in HTML 4.01 and is obsolete in HTML5. All alignment should be done with CSS.

The <center> element was essentially a shortcut for <div align="center">. Both approaches are now obsolete because they embed presentation in the HTML structure. CSS provides much more flexible and powerful centering options.

Syntax

<center>content to center</center>

The element required both opening and closing tags and acted as a block-level container.

Modern Alternatives

Use CSS properties instead of the <center> element:

Old HTML (Deprecated)

<center>
  <p>This text is centered.</p>
  <img src="photo.jpg" alt="Photo">
</center>

Modern CSS for Text

<p style="text-align: center;">This text is centered.</p>

Modern CSS for Block Elements

<!-- HTML -->
<div class="centered-block">
  <img src="photo.jpg" alt="Photo">
</div>

<!-- CSS -->
.centered-block {
  text-align: center;
}

Modern CSS for Container Centering

<!-- CSS for centering a block element itself -->
.centered-container {
  margin: 0 auto;
  width: 80%;
}

Modern Flexbox Centering

.flex-center {
  display: flex;
  justify-content: center;
  align-items: center;
}

When to Avoid

Always avoid using <center>. There is no valid use case for this element in modern HTML:

  • It mixes presentation with structure
  • It provides less control than CSS alternatives
  • It fails validation for HTML5 documents
  • CSS offers multiple centering methods for different scenarios
  • Flexbox and Grid provide superior layout control
  • <div> - Generic block container, use with CSS for alignment
  • <p> - Paragraph element, can be centered with CSS
  • <style> - Embed CSS styles for proper alignment