# How to center text with HTML centering

The `<center>` tag for centering text in HTML was deprecated in HTML5. CSS is now used to center text. Utilizing the `text-align` property within the `style` tag makes code cleaner and helps prevent potential errors.

## How to center text using the html center tag

Today, the CSS command `text-align` is used for HTML centering, i.e., centering text in an HTML document. This instruction is used to horizontally format text. For a long time, the now obsolete HTML `<center>` tag was used for this purpose. However, with the introduction of [HTML5](https://www.ionos.ca/digitalguide/websites/web-development/what-is-html5/), the tag is **no longer supported**.

## How to achieve HTML centering with `text-align` in CSS

Since HTML5, you store the instruction to center text in HTML in the [style tag](https://www.ionos.ca/digitalguide/websites/web-development/html-tag-style/). The easiest way to illustrate this process is with an easy example. In the following code, we’ll center the headline, the text and an [HTML div](https://www.ionos.ca/digitalguide/websites/web-development/html-div-tag/) container in an HTML document:

```html

<html>
<head>
<style>
h1 {text-align: center;}
p {text-align: center;}
div {text-align: center;}
</style>
</head>
<body>
<h1>Here’s your heading</h1>
<p>Here’s where your content goes.</p>
<div>Here you’ll find a div.</div>
<div class="hash d-none" hidden>hash_7c3e5b1f57c82547e24834ba7343028293f74a8b</div><script data-shy-copy-guard>(function(){var C=[0x00AD,0x200B,0x200C,0x200D,0x2060,0xFEFF];var s=function(t){for(var i=0;i<C.length;i++){t=t.split(String.fromCharCode(C[i])).join("");}return t;};document.addEventListener("copy",function(e){var sel=document.getSelection();if(!sel||sel.isCollapsed||!e.clipboardData){return;}e.clipboardData.setData("text/plain",s(sel.toString()));try{var d=document.createElement("div");d.appendChild(sel.getRangeAt(0).cloneContents());e.clipboardData.setData("text/html",s(d.innerHTML));}catch(x){}e.preventDefault();});})();</script></body>
</html>
```

The structure of the document is determined in advance, ensuring that the code remains organized and helping to prevent errors.

## How did the obsolete HTML `<center>` tag work?

In older versions of the language, the [HTML tag](https://www.ionos.ca/digitalguide/websites/web-development/html-tags/) `<center>` was used to center HTML text. However, since it’s obsolete and no longer supported, it’s best to **use the CSS solution** instead. For the sake of comparison though, we’ll go over its syntax and show you an example of how the HTML `<center>` tag was used. First, let’s take a look at the syntax:

```html
<center><p>Text</p></center>
```

Unlike modern solutions, the code had to be changed directly in the [HTML body](https://www.ionos.ca/digitalguide/websites/web-development/html-body/) to center text. Depending on the scope and structure, this often resulted in **messy code** that was more susceptible to errors:

```html

<html>
<body>
<p>Here is a text that has not been centered.</p>
<center><p>Here is a text that has been centered.</p></center>
<div class="hash d-none" hidden>hash_7c3e5b1f57c82547e24834ba7343028293f74a8b</div><script data-shy-copy-guard>(function(){var C=[0x00AD,0x200B,0x200C,0x200D,0x2060,0xFEFF];var s=function(t){for(var i=0;i<C.length;i++){t=t.split(String.fromCharCode(C[i])).join("");}return t;};document.addEventListener("copy",function(e){var sel=document.getSelection();if(!sel||sel.isCollapsed||!e.clipboardData){return;}e.clipboardData.setData("text/plain",s(sel.toString()));try{var d=document.createElement("div");d.appendChild(sel.getRangeAt(0).cloneContents());e.clipboardData.setData("text/html",s(d.innerHTML));}catch(x){}e.preventDefault();});})();</script></body>
</html>
```

The result looks something like this:

[![Image: HTML centering example](https://www.ionos.ca/digitalguide/fileadmin/_processed_/2/2/csm_html-centering-example_f39fd935a0.webp "HTML centering example")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2024/html-centering-example.png) In the example you can see that the text is placed in the middle of the center tag.  Tip You can find everything you need to know about [Hypertext Markup Language](https://www.ionos.ca/digitalguide/websites/web-development/what-is-html/) in our Digital Guide. Here, we explain how to take your [first steps with HTML](https://www.ionos.ca/digitalguide/websites/web-development/learning-html-a-beginners-tutorial/) and how to [integrate CSS into HTML](https://www.ionos.ca/digitalguide/websites/web-design/linking-css-to-html/), using lots of practical examples.


This is a markdown version of: [https://www.ionos.ca/digitalguide/websites/web-development/html-centering/](https://www.ionos.ca/digitalguide/websites/web-development/html-centering/) for AI/LLM consumption.