Q:

How do you center text in HTML?

A:

Quick Answer

To center text in HTML, apply the "text-align: center;" CSS property to the HTML block element ("div," "p" or "span" set to "display: block;") wrapping your content. Some browsers allow the use of "center" HTML tags and the "align" attribute, but these are considered obsolete in the latest HTML specification.

Continue Reading

Full Answer

  1. Identify the HTML block element wrapping the content to center

    Open your HTML document in a code editor and look for the text you want to center. By working your way up the hierarchy of HTML elements, identify the block element that contains it. Text is usually contained inside a paragraph, or "p," element, but if you want to center multiple paragraphs, then it might be best to apply the style to a parent element, such as a "div" holding all the "p" elements you want to center.

  2. Apply "text-align: center;" to the HTML element

    Add ' style="text-align: center;" ' after the name of the HTML wrapping the text you want to center. For example, if you are trying to center text within a paragraph element, the code between the lesser-than and greater-than symbols of the tag should look like ' p style="text-align: center;" '.

  3. Test the change

    Save your HTML document, and open it in a Web browser. If the "text-align" CSS property was applied correctly, the text should be centered within the width of its parent element.

Learn more about Computer Programming

Related Questions

Explore