HTML

HTML Center Text: Syntax, Usage, and Examples

Centering text in HTML helps you align content for better visual balance. Whether you're designing headers, call-to-actions, or footers, the ability to center text using HTML and CSS gives you more control over layout and presentation. Although early HTML provided a tag specifically for this purpose, modern web design uses CSS for more flexibility and consistency.

How to Center Text in HTML

The old-school way to center text in HTML involved using the <center> tag:

<center>This text is centered using the center tag.</center>

However, the <center> tag is obsolete in HTML5. It still works in many browsers, but you should avoid it in modern projects. The better approach is to use CSS—especially the text-align: center rule.

Using Inline CSS

You can center text with the style attribute on almost any block-level element.

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

This is one of the simplest and most direct ways to center text using HTML and CSS together.

Using Internal CSS

Define a class in a <style> block inside your HTML document:

<style>
  .center-text {
    text-align: center;
  }
</style>

<p class="center-text">This text is centered using a CSS class.</p>

This method is clean, reusable, and helps separate content from presentation.

Using External CSS

For larger projects, define styles in an external stylesheet.

.centered {
  text-align: center;
}

Then reference it in your HTML:

<link rel="stylesheet" href="styles.css">
<h2 class="centered">This heading is centered.</h2>

Using external stylesheets helps maintain consistency across an entire website.

When to Use Center Text HTML

Centering text isn’t just for aesthetics—it can guide the reader’s attention and improve the structure of your page.

Highlighting Headlines or Titles

Titles and headers often look better when centered. This makes the section feel more structured and helps highlight the headline.

<h1 style="text-align: center;">Welcome to My Website</h1>

Centering Call-to-Actions

Calls to action (CTAs) like “Sign up now” or “Learn more” stand out more when centered on the page.

<p style="text-align: center;"><a href="#">Sign Up Today</a></p>

This draws the user’s attention and makes the CTA more noticeable.

Formatting Footers

Footers often use centered text for copyright notices, legal disclaimers, or navigation links.

<footer style="text-align: center;">
  &copy; 2025 Your Company. All rights reserved.
</footer>

Centering creates a clean and consistent finish to the page layout.

Examples of HTML Center Text

Let’s look at more ways to use center text HTML in different contexts.

Basic Paragraph Centering

<p style="text-align: center;">Centered paragraph using inline CSS.</p>

This is fast and easy for single-use text blocks.

Centering with Div Containers

You can wrap content inside a <div> and center all child elements at once.

<div style="text-align: center;">
  <h2>Centered Title</h2>
  <p>This whole block is centered.</p>
</div>

This works well for grouping multiple elements that share the same alignment.

Centering Text in Tables

Apply text-align: center to table cells:

<table border="1">
  <tr>
    <th style="text-align: center;">Name</th>
    <th style="text-align: center;">Age</th>
  </tr>
  <tr>
    <td style="text-align: center;">Jordan</td>
    <td style="text-align: center;">28</td>
  </tr>
</table>

This keeps your data cleanly aligned and easier to scan.

Using Classes for Reusability

<style>
  .centered-text {
    text-align: center;
    font-size: 18px;
    color: navy;
  }
</style>

<p class="centered-text">Reusable centered paragraph with style.</p>

Use this when you need to apply the same centered style across multiple elements.

Learn More About How to Center Align Text in HTML

How to Center the Text in HTML for Forms

Place form labels, fields, and buttons in a container and apply text-align: center.

<div style="text-align: center;">
  <label for="email">Email:</label>
  <input type="email" id="email">
  <br><br>
  <button>Submit</button>
</div>

This gives the form a more balanced and symmetrical appearance.

How Do I Center Text in HTML Without Inline Styles?

Use internal or external CSS for a cleaner and more scalable approach.

<style>
  .form-header {
    text-align: center;
    font-weight: bold;
  }
</style>

<h3 class="form-header">Please Fill Out the Form</h3>

Avoiding inline styles helps separate design logic from content, which makes your code easier to manage in the long run.

How to Center Align Text in HTML Emails

In HTML emails, inline CSS is often required due to limited support for modern CSS:

<td style="text-align: center;">
  <p style="margin: 0;">Centered text inside an email table cell.</p>
</td>

Test your emails in different clients to ensure the alignment looks right everywhere.

Responsive Centering for Mobile Devices

To center text that remains centered across screen sizes, use media queries and relative units:

<style>
  .responsive-center {
    text-align: center;
    font-size: 1.2rem;
  }

  @media (max-width: 600px) {
    .responsive-center {
      font-size: 1rem;
    }
  }
</style>

<p class="responsive-center">This text adjusts size and stays centered.</p>

This ensures good readability and alignment on smaller screens.

Center Text HTML and Accessibility

When you center text using HTML and CSS, always keep readability in mind. For long blocks of text, centered alignment can make it harder to follow from line to line—especially for users with dyslexia or low vision. Reserve center alignment for short content like headlines, buttons, or captions.

If you're working on a site with accessibility goals, use semantic tags and maintain clear structure. Avoid relying on alignment alone to communicate meaning.

Centering Text Alongside Images

If you want text centered below an image, wrap both in a block-level element with text-align: center:

<div style="text-align: center;">
  <img src="product.jpg" alt="Product Image" width="200">
  <p>Our latest release</p>
</div>

This keeps the image and caption aligned together as a single unit.

Using Flexbox for Centering Everything

Flexbox allows you to center text both horizontally and vertically—something text-align: center can't do on its own.

<div style="display: flex; justify-content: center; align-items: center; height: 100px;">
  <p>Centered horizontally and vertically</p>
</div>

This is useful for banners, buttons, and full-page layouts.

Using HTML center text techniques effectively means more than just aligning text to the middle of the screen. It’s about using CSS properly, writing clean and maintainable code, and considering your layout and audience. Whether you use inline styles, classes, or advanced methods like flexbox, center text HTML methods help you deliver clearer, more visually appealing pages.

So next time you're wondering how to center align text in HTML or how to center the text in HTML layouts, you’ll have a toolbox full of practical and modern techniques—no <center> tag required.

Learn HTML for Free
Start learning now
button icon
To advance beyond this tutorial and learn HTML by doing, try the interactive experience of Mimo. Whether you're starting from scratch or brushing up your coding skills, Mimo helps you take your coding journey above and beyond.

Sign up or download Mimo from the App Store or Google Play to enhance your programming skills and prepare for a career in tech.

You can code, too.

© 2025 Mimo GmbH