ICT Button with Arrow Green Leaf Toucan Extended

We help businesses stand out, so they significantly increase their chance of converting more leads

+ 0 %
Increase in conversion off a high base - Manufacturer
0 %
Increase on conversion rate - B2B Service Business
+ 0 %
Increase on leads with a simple 1 page UX/UI revamp - B2B
+ 0
Awards & mentions across 4 different industries since 2009

Need a strategy?
Let’s point you in
the right direction

Required fields

Call us curious cats...

Blog

29 Jan 25

How To Center Text In HTML?

Chromatix | Web Development

Alright—centering text sounds simple. And sometimes, it is. But depending on your page layout, container types, or the weird little quirks of browsers, there’s actually a few ways to approach it. Some better than others.

Over the years, I’ve had countless clients ask: “Why is this text not centered properly?”

Well. Let’s run through the main ways you can center text in HTML and CSS. I’ll keep it practical, like I would if we were mapping it out on a whiteboard.

 

The Basics: HTML vs CSS

First up. HTML on its own doesn’t give you much. CSS is where all the heavy lifting happens.

Technically, HTML does have a <center> tag (more on that in a sec), but in 2025? You want to avoid that. CSS gives you better control, it plays nicer with responsive designs, and it keeps your code tidy for the long haul.

 

5 Solid Ways To Center Text

1) The Old <center> Tag (Don’t Do This… Anymore)

Yeah, back in the early 2000s, we all used:

<center>This text is centered</center>
 

It worked. It still technically works. But it’s been deprecated for years now. Google won’t like it. Screen readers don’t love it. And if you’re building anything modern (which you should be), you want to avoid leaning on old-school tags like this.

2) The Quick & Easy text-align: center;

This one still works great for simple horizontal centering.

<div style="text-align: center;">This text is centered</div>
You pop it on the parent container, and all inline content inside centers itself. Easy win for headings, paragraphs, buttons inside a block element. Honestly, I probably still use this 50 times a week when mocking up layouts.
 

3) Flexbox — My Personal Go-To

Flexbox is a bit of a game changer. When I was working on a site for a client called EcoFit last month, we used Flexbox to handle all their call-to-actions across mobile and desktop. Zero headaches.

Here’s a full center (both horizontal and vertical):

<div style="display: flex; justify-content: center; align-items: center; height: 100vh;">
This text is centered using Flexbox
</div>
  • justify-content: center handles horizontal

  • align-items: center handles vertical

  • And height: 100vh makes sure it takes up the full viewport

Perfect for hero banners, landing pages, or full-screen modals.

4) CSS Grid — Super Clean For Complex Layouts

Grid is Flexbox’s cooler cousin. Similar idea, slightly different vibe.

<div style="display: grid; place-items: center; height: 100vh;">
This text is centered using CSS Grid
</div>
  • place-items: center is shorthand for both vertical and horizontal centering.

  • I tend to use Grid when I’m dealing with multi-column layouts or more complex page structures.

We used this recently for a client’s product catalog where Flexbox was just getting messy.

5) The margin: auto Trick

Sometimes, you’re just trying to center a block-level element. This still works like a charm—as long as you give the element a width.

<div style="width: 50%; margin: auto;">This block is centered</div>
 
  • The browser automatically calculates the left and right margins.

  • Great for cards, containers, or images where you don’t need full viewport alignment.

 

Some Real-World Considerations

Before you pick your method, let’s touch on a few things I always remind my team:

  • Responsiveness matters: Flexbox and Grid handle screen sizes better. Don’t break your layout on mobile.

  • Vertical centering used to be a nightmare: Flexbox and Grid basically solved that.

  • Accessibility isn’t optional: Don’t center huge blocks of text just because it “looks nice.” Think readability.

  • Avoid hard-coding absolute positions: Unless you love debugging for hours. Seriously.

 

So… Which Method Should You Use?

Honestly? Depends on the situation.

  • Quick headings? Use text-align: center.

  • Full-page layouts? Flexbox or Grid.

  • Block containers? margin: auto still holds up.

Most of my own builds default to Flexbox first. It just handles the most common use cases with minimal code.

If you’re still stuck—or if your layout just isn’t playing nice—sometimes it’s worth having a pro take a look. At Chromatix, we’ve been wrangling HTML, CSS, and everything in between for years. We can make sure your text sits where it should—and more importantly, help your whole site convert better.

By the way — what’s your most frustrating centering issue you’ve hit lately?

Google Review Image