Centering text is generally used for a title of a website or document. To center text using HTML, you can use the

tag or use a CSS property. To proceed, select the option you prefer and follow the instructions.

Using the
tags

One way to center text or put it in the middle of the page is to enclose it within

tags.

  • Using the
    tags.
  • Using a style sheet property.
Center this text!

Inserting this text within HTML code would yield the following result:

Center this text!

Using a style sheet property

You can center the text of a website with CSS by specifying the text-align property of the element to be centered.

The

tag is now considered deprecated. Although it may still work, it’s expected to be removed in favor of using CSS. We recommend you use the style sheet method (shown below) to center text in HTML.

Centering a few blocks of text

If you only have one or a few blocks of text to center, add the style attribute to the element’s opening tag and use the “text-align” property. In the example below, we’ve added them to the

tag.

Center this text!

The “text-align” property is set to “center” to indicate the element is centered in the middle of the page or containing div.

Multiple blocks of text

If you have many blocks of text to center, use CSS inside tags in the head section or in an external style sheet. See the example code below for how to set all text inside the

tags to be centered.

The text in every set of

tags is centered on the page. If you would like some paragraphs centered, while others are not, you can create a style class, as seen in the code below.

If you’re creating a center class, as shown in the example above, a paragraph can be centered using the code below, which “calls” the center class.

Center this text!

Once a class is created, it can be applied to any HTML tag containing words, images, and most other elements. For example, if you wanted the heading to be centered, you could add class=“center” to the

tag or another heading tag.

  • How to center a picture on a web page using HTML.
  • How to change the font type, size, and color on a web page.
  • See the center definition for further information and related links.
  • HTML and web design help and support.