Close
    Search Search

    How to center HTML text

    Index

    Center the text in HTML with the align attribute

    If you want center the HTML text, all you have to do is learn how to use the attribute correctly align, which can be used in multiple contexts: thanks to it, it is in fact possible to align texts, images, tables and so on. Let's find out how to insert it both inside the tag  than in the tag .



    Tag

    How to center HTML text

    To get a center-aligned text via the align attribute and tag, you have to proceed as follows: first open your favorite HTML editor, insert the tag (which in case you didn't know it stands for Paragraph, paragraph in cittàn) followed by the attribute align and the attribute corresponding to the desired formatting style, that is center (centered) enclosed in quotation marks. In this case, the code to be used to obtain the desired result is the following.

    Test text

    Using the code that I have just indicated you will be able to obtain the result you see below, that is a text perfectly aligned in the center of the page in which it is inserted.

    Test text

    With the same technique, you can also align text left, right, or even justify it. To proceed, all you have to do is replace align=”center” with one of the following attributes.

    • align=”left” - if you intend to align the text to the left.
    • align=”right” - if you want to right align the text.
    • align=”justify” - if, on the other hand, you intend to justify the text.

    Tag

    How to center HTML text


    As I said earlier, it is also possible to center the text in HTML using the tag  which, as you may already know, differs from the one analyzed previously by the fact that it does not create paragraphs (so it does not leave a blank line at its end) and can be used as a generic container for multiple elements, so not only textual content but also tables, images and so on.


    To get a text centered with the tag in question, even in this case all you have to do is open the HTML editor you are using to create your Web page "by hand", insert the tag followed by the attribute align and specify between quotation marks the desired formatting style, in this case center, that is, centered. Below you will find a practical example that will be useful for you to understand even better how to proceed.

    Test text

    The code in question will allow you to obtain the following result, that is a text perfectly aligned in the center of the page in which it is inserted:

    Even the tag it does not just center text, it can also be used to align texts left, right or justify them. Just replace the attribute align=”center” with one of those listed below.

    • align=”left” - if you intend to align the text to the left.
    • align=”right” - if you want to right align the text.
    • align=”justify” - if, on the other hand, you wish to justify the text.

    In any case, for the sake of "cleaning" the code, I recommend that you always use the tag (especially with regards to the lyrics) and not the tag . Understood?


    Center the text in HTML with the tag center

    How to center HTML text


    Another way to center the text in HTML is to resort touse of the tag center, which offers the advantage of being able to center multiple paragraphs at a time. All you have to do to use it is open the HTML editor you are using to practice, insert the tag followed by the text you want to center and the closing tag , which must be inserted at the point on the page where you want to stop using centered formatting.


    If you want to center only one paragraph, for example, you can proceed as you see in the following example.

    Sample text

    The result you will get will be the following.

    Sample text

    If, on the other hand, you want to center several paragraphs at a time, all you have to do is enclose them all within the tag . This is one of the advantages of using this tag in place of the attribute align (which you should have put inside each tag to get the same result). If you want to center more paragraphs, then, follow the steps below.

    Example text paragraph no. 1

    Example text paragraph no. 2

    Example text paragraph no. 3

    Paragraph sample text ...


    The result you will get using the code I just indicated will be paragraphs aligned all in the center of the page in which they are inserted, as you can see in the example below.

    Example text paragraph no. 1

    Example text paragraph no. 2

    Example text paragraph no. 4

    Paragraph sample text ...

    And that's it! Now that you know the basic rules for centering text in HTML, all you have to do is practice, practice and, again, practice! By doing so, you will become more and more familiar with the use of the tags and attributes I have told you about in this guide and you will be able to format the texts to insert on your web page without any difficulty. In this regard, I suggest you also consult my guide on how to create a site in HTML, in which I have explained to you in more detail how to build a site using only the code.

    How to center HTML text

    add a comment of How to center HTML text
    Comment sent successfully! We will review it in the next few hours.