<center>
NOT supported in HTML5. Use CSS instead.
⚠️ DEPRECATEDDefinition and Usage
The
<center> tag is NOT supported in HTML5. Use CSS properties like text-align, margin, flexbox, or grid instead.
The <center> tag was used in older HTML versions to center-align text and other elements horizontally within their containing element.
This tag mixed presentation with content structure, which goes against modern web development best practices of separating content (HTML) from presentation (CSS).
<center> tag for backward compatibility, you should never use it in new projects. Always use CSS for styling and layout.
Browser Support
The <center> tag is NOT supported in HTML5:
Old Usage (HTML 4)
In older HTML versions, the <center> tag was used to center content:
Old HTML 4 Example (Don't Use)
<!-- HTML 4 - DEPRECATED -->
<center>
<h1>Welcome to My Website</h1>
<p>This content is centered.</p>
</center>
Modern CSS Alternatives
Here are the correct modern ways to center content using CSS:
1. Text-Align for Inline Content
Use text-align: center for centering text and inline elements:
<center>
<p>Centered text</p>
</center>
<div style="text-align: center;">
<p>Centered text</p>
</div>
2. Margin Auto for Block Elements
Use margin: 0 auto to center block-level elements:
<center>
<div style="width: 300px;">
Content
</div>
</center>
<div style="width: 300px; margin: 0 auto;">
Content
</div>
3. Flexbox for Centering (Horizontal & Vertical)
Use Flexbox for powerful centering capabilities:
Horizontal Centering with Flexbox
<div style="display: flex; justify-content: center;">
<p>Centered content</p>
</div>
Horizontal and Vertical Centering with Flexbox
<div style="display: flex;
justify-content: center;
align-items: center;
height: 300px;">
<p>Perfectly centered!</p>
</div>
4. CSS Grid for Centering
Use CSS Grid for modern centering:
Grid Centering
<div style="display: grid;
place-items: center;
height: 300px;">
<p>Centered with Grid</p>
</div>
5. Absolute Positioning with Transform
For absolute positioning scenarios:
Centering with Position
<div style="position: relative; height: 300px;">
<div style="position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);">
Centered content
</div>
</div>
Complete Migration Examples
Example 1: Centered Heading
<center>
<h1>Page Title</h1>
</center>
<h1 style="text-align: center;">
Page Title
</h1>
Example 2: Centered Button
<center>
<button>Click Me</button>
</center>
<div style="text-align: center;">
<button>Click Me</button>
</div>
Example 3: Centered Container
<center>
<div style="width: 600px;">
Content here
</div>
</center>
<div style="width: 600px;
margin-left: auto;
margin-right: auto;">
Content here
</div>
Example 4: Centered Image
<center>
<img src="logo.png" alt="Logo">
</center>
<img src="logo.png"
alt="Logo"
style="display: block;
margin: 0 auto;">
Example 5: Multiple Centered Elements
<center>
<h1>Title</h1>
<p>Paragraph</p>
<button>Button</button>
</center>
<div style="text-align: center;">
<h1>Title</h1>
<p>Paragraph</p>
<button>Button</button>
</div>
CSS Centering Methods Comparison
| Method | Best For | CSS Code |
|---|---|---|
| text-align | Text and inline elements | text-align: center; |
| margin auto | Block elements with fixed width | margin: 0 auto; |
| Flexbox | Any content, horizontal & vertical | display: flex; justify-content: center; |
| Grid | Modern layouts, perfect centering | display: grid; place-items: center; |
| Absolute + Transform | Overlays, modals, positioned elements | position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); |
Migration Guide
- Find all instances: Search your codebase for
<center>tags - Identify content type:
- Text/inline elements → Use
text-align: center - Block elements with width → Use
margin: 0 auto - Complex layouts → Use Flexbox or Grid
- Images → Use
display: block; margin: 0 auto
- Text/inline elements → Use
- Apply CSS: Add appropriate CSS to parent element or create CSS class
- Remove tag: Delete the
<center>opening and closing tags - Test thoroughly: Verify centering works across different screen sizes
Why Was It Deprecated?
- Separation of Concerns: HTML should define structure, CSS should handle presentation
- Maintainability: CSS makes it easier to update styles across entire websites
- Flexibility: CSS offers many more centering options than the
<center>tag - Responsive Design: CSS allows different centering behavior on different screen sizes
- Semantic HTML: Div elements with CSS are more semantically neutral
- Accessibility: Proper semantic HTML with CSS styling improves accessibility
- Modern Standards: HTML5 emphasizes semantic markup over presentational tags
Try it Yourself
Modern Centering Example
See how modern CSS centering works:
Text-Align Method
This text is centered using text-align: center
Flexbox Method
This box is centered using Flexbox
Grid Method
This box is centered using CSS Grid
Best Practices
- Never use <center> tag: Always use CSS for centering
- Use appropriate method: Choose the right CSS centering technique for your use case
- Consider responsiveness: Test centering on different screen sizes
- Create reusable classes: Define CSS classes for common centering patterns
- Use Flexbox/Grid: For complex layouts, prefer modern layout methods
- Semantic HTML: Use appropriate HTML elements with CSS styling
- Validate your code: Ensure HTML5 compliance by avoiding deprecated tags
HTML Free Codes