Live Preview
How <center> looked historically (browsers still render it for compatibility):
Centered Heading
Center-aligned paragraph text

By the end of this tutorial, you’ll understand legacy centering markup and the modern CSS techniques that replaced it.
How <center> horizontally aligned child content.
Why HTML5 removed <center> from the specification.
Center inline text and headings with CSS.
Center block-level boxes with a fixed width.
Center content horizontally and vertically in containers.
Recognize center in old tutorials and migrate to CSS.
<center> Tag?The <center> element was a block-level HTML tag that aligned its child content to the horizontal center of its container. It could wrap headings, paragraphs, images, and other elements.
Do not use <center> in new projects. Use CSS text-align, margin: 0 auto, or flexbox instead. Browsers still render the tag for backward compatibility only.
HTML5 moved presentational alignment to stylesheets. Learn <center> to read legacy HTML, but center content with CSS in all new work.
.centered-text { text-align: center; }
.centered-box { margin: 0 auto; width: 300px; }Wrap content between opening and closing <center> tags:
<center>Your Centered Content Here</center><center> is a block element—it wraps multiple child elements.<center />) is not valid in HTML.<center> tags unnecessarily.| Use Case | Code Snippet | Notes |
|---|---|---|
| Legacy centering | <center>Text</center> | Obsolete — legacy render |
| Center text | text-align: center; | Preferred for headings and paragraphs |
| Center block box | margin: 0 auto; | Requires a set width on the element |
| Flexbox center | justify-content: center; | Horizontal and vertical centering |
| Tag-specific attrs | None | Global attributes only |
| HTML5 status | Obsolete | Removed from specification |
<center> vs CSS CenteringChoose the right technique based on what you need to center:
| Method | Best for | HTML5 status |
|---|---|---|
<center> | Nothing — do not use | Obsolete |
text-align: center | Inline text, headings, links | Modern CSS standard |
margin: 0 auto | Fixed-width divs, images, cards | Modern CSS standard |
| Flexbox | Responsive horizontal and vertical centering | Modern CSS standard |
The <center> tag had no tag-specific attributes. Global attributes could be applied, but CSS classes are the proper approach today:
class / id GlobalHook for CSS selectors—prefer a class with text-align instead of center.
<div class="centered-text">style InlineInline text-align: center works but external CSS is cleaner.
style="text-align: center;"Element status ObsoleteThe entire <center> element is removed from HTML5.
/* use CSS instead */The entire <center> element is obsolete. Use CSS for all alignment in new projects.
Historical <center> patterns plus modern CSS replacements. Legacy examples render for compatibility only—do not use in new code.
How <center> looked historically (browsers still render it for compatibility):
Center-aligned paragraph text
The classic use: wrap a heading and paragraph inside <center> to align them horizontally.
<center>
<h2>Centered Heading</h2>
<p>Center-aligned paragraph text</p>
</center>Developers once used <center> for page titles, image alignment, and navigation bars. Today use CSS for all alignment and layout.
Center inline text and headings with text-align: center on a container or element.
.centered-text {
text-align: center;
}Center a block-level box (like a card or image) by giving it a width and setting margin: 0 auto.
.centered-box {
width: 240px;
margin: 0 auto;
padding: 1rem;
background: #dbeafe;
}Use flexbox when you need to center content both horizontally and vertically inside a container.
.flex-center {
display: flex;
justify-content: center;
align-items: center;
min-height: 120px;
}Three modern techniques replace the obsolete <center> tag:
text-align Inline text centeringmargin: 0 auto Block box centeringflexbox Flexible layout centeringgrid place-items: center/* Center text */
.centered-text {
text-align: center;
}
/* Center a block box */
.centered-box {
width: 300px;
margin: 0 auto;
}
/* Flexbox centering */
.flex-center {
display: flex;
justify-content: center;
align-items: center;
}Live CSS-centered heading
No obsolete HTML tags needed.
Centering is visual layout, not semantic meaning:
Place headings, text, or images inside center tags.
User-agent styles centered inline and block content within the element.
HTML5 moved alignment to stylesheets for cleaner, maintainable code.
Learn center for history. Use text-align, margin, or flexbox in all new projects.
Browsers still render <center> for backward compatibility, but the element is obsolete and not part of HTML5.
All major browsers still apply default styles to <center> for old pages, but the tag is removed from the HTML5 specification. Never use it in new projects.
HTML5 separated structure from presentation—alignment belongs in CSS.
Bottom line: Browsers still render <center> for old pages, but it is obsolete. Use CSS centering in all new projects.
The <center> tag is obsolete HTML—recognize it in old tutorials, but use CSS for centering in real projects. Choose text-align for text, margin: 0 auto for block boxes, and flexbox when you need flexible layout control.
text-align: center for textmargin: 0 auto for centered block elementscenter only to read legacy HTML<center> in new HTML code<center> tags unnecessarilyalign attribute<center>Bookmark these before you ship — they’ll keep your layouts modern and maintainable.
<center> aligned child content to the horizontal center.
Removed from the spec—not for new projects.
StatusUse text-align: center for inline text and headings.
Centers block-level boxes with a defined width.
LayoutBest for responsive horizontal and vertical alignment.
ModernBrowsers still render it for backward compatibility only.
Compatibilitytext-align: center for text, margin: 0 auto for block elements, and flexbox for flexible layouts.center only to understand old HTML you may encounter.Skip obsolete center. Practice CSS text-align and flexbox centering in the Try It editor.
6 people found this page helpful