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