What is the HTML <center> tag?

Overview

Traditionally in HTMLHypertext Markup Language, we use the <center> tag to align text in a centered horizontal manner. This <center> element is no longer supported in HTML5, as it got deprecated in HTML4.

Now the CSSCascading Style Sheets text-align property provides multiple features to align text or blocks of text such as:

  • margin-right
  • margin-left
  • auto

We can apply these attributes individually on blocks like <div>, <p>, etc.

Syntax


<center> content will be here.... </center>

CSS property text-align

For the latest browsers, we can use CSS to align text in different ways such as: center, right, and left.

We can use CSS in different ways, as shown below.

  • style attribute on <p>

<p> 
  This line will be centered.<br> am I centered aligned?
</p>

  • style attribute on <div>

<div> This text will be centered.
   <p> hello, I am centered aligned. </p>
</div>

Code

This code snippet shows how to use the <center> element in your HTML code. This prints the <p> (paragraph) tag as centered text using CSS to increase the font-size and its color.

  • HTML
  • CSS (SCSS)

Free Resources