How to Center Text in HTML

Author: Laura McKinney
Date Of Creation: 10 August 2021
Update Date: 1 July 2024
Anonim
How to Create Web Pages Using HTML : How to Center Text in HTML
Video: How to Create Web Pages Using HTML : How to Center Text in HTML

Content

This wikiHow teaches you how to center text on HTML website using Cascading Style Sheets (CSS). Centering text in HTML is done with tags

, but this tag is considered outdated and no longer works on most browsers.

Steps

Method 1 of 2: By CSS

  1. Open the file containing the CSS styles. Though the card
    outdated, but you can still create new elements to add anywhere on the page to center the text within their boundaries. If you don't have a separate CSS file, you need to specify the style at the top of the HTML file, between the "tags.’.
    • If no card yet You need to add directly below the card at the top of the file are as follows:

  2. Create text center layer. Card
    will ask the HTML document to reference the specific portion of text, so you'll need to classify this tag. Please enter the following text in the space between the "style" tag, do not forget to press ↵ Enter twice after the first line:

    • Add properties text-align. Import text-align: center; into the space between the braces in the section div.a. The current title will look like this:

      • Add a card div text should be centered. Proceed by placing the card
        text above the text you want to center and close with tags below the text you want to center. For example, to center a title and the opening paragraph, you need to type the following:
        • Use of cards div.a to center the other regions. If you want to center another element (for example, content between tags like and

          ), enter
          in front of the text and in after that. Since you specified "div.a" as the centering command, this text will center just like the previous one:
          • Document review. The contents may vary, but in general your document should now look something like this:
              advertisement

            Method 2 of 2: Use the center tag in HTML

            1. Open the HTML document. This method describes how to use HTML tags
              (now outdated as well). As of December 2018, this card is still active in some web browsers, but in the long term, you should still not use this card.
            2. Identify the text that you want to center. Scroll down until you find the title, paragraph, or other text you want to center.
            3. Add a "center" tag to the ends of your text. This center tag has a format
              text
              , where "text" is the text to be centered. If the text already has an inner tag (for example, "" for the paragraph), the "center" tag can be outside of any pre-existing tags:
              • Review the HTML document. The document should now look like this:
                  advertisement