How to center a text in HTML

Centering text is generally used for a title of a website or document. To center text using HTML, you can use the <center> tag. To proceed, select the option you prefer and follow the instructions.

Using the <center></center> tags

One way to center text or put it in the middle of the page is to enclose it in<center></center>tags.

<center>Center this text!</center>

Using the example HTML code above yields the following result:

Center this text!

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 added the attribute and property to the <p> tag.

<p style=”text-align:center”>Center this text!</p>

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

Read More

HOW TO CREATE A PORTFOLIO USING HTML

Examples of centered text and objects

Below are examples of using the style attribute and “text-align” property to center text and objects on a web page.

Centering text in a paragraph

HTML code:

<p style=”text-align:center”>Example of centered text in a paragraph.</p>

Result:

Example of centered text in a paragraph.

Conclusion

Thanks for following our website if you can add text now then please share your thoughts in our comment box on your social media.

Leave a Comment