How to Center Text in HTML
How to Center Text in HTML
This wikiHow teaches you how to center text in an HTML website using Cascading Style Sheets (CSS). Centering in HTML used to be done with the
tag, but that tag is now considered obsolete and no longer works in most browsers.[1]
X
Research source
Steps

Using CSS

Open the file that contains your CSS styles. Though the

tag is obsolete, you can create a new element to add to any part of a page to center text within its boundaries. If you don't have a separate file for your CSS, you'll find the styles at the top of the HTML file between the "" tags. If you don't already have tags, add them directly below at the top of the file like this:

Create a class that centers text. The

tag will tell your HTML document to reference a specified section of text, so you'll create a class for that tag. Type the following into the space between the "style" tags, making sure to press ↵ Enter twice after the first line: div.a { }

Add the text-align property. Type text-align: center; into the space between the two curly brackets in the div.a section. The header should now look like this:

Add the proper div tag to text that should be centered. You'll do this by placing the

tag above the text you want to center and closing with a
tag below the text you want to center. For example, to center a header and its paragraph text, you would enter the following:

Welcome to My Website

This website is primarily for the purpose of providing information about things.

Use the div.a tag to center other areas. To center another element (e.g., content between tags like

and

), type
before the item, and
after it. Since you already have "div.a" specified as the centering command, this will center the text just like it did before:

Donations Welcome

please

Review your document. Though the content will vary, your document should look something like this:

Welcome to My Website

This website is primarily for the purpose of providing information about things.

Donations Welcome

please

Using the Center Tag in HTML

Open your HTML document. This method describes how to use the HTML

tag, which is now obsolete. As of December 2018, this tag may still work in some web browsers, however, it's not advised to rely on this tag in the long run.

Find the text you want to center. Scroll down until you find the header, paragraph, or other text that you want to center.

Add the "center" tag to each side of the text. The center tag is in the format

text
where "text" is your text. If your text has tags on it (e.g., "

" for paragraph text), the "center" tags can go outside the existing tags:

Welcome to My Website

Make yourself at home!

Review your HTML document. Your document should look something like this:

Welcome to My Website

Make yourself at home!
The purpose of this website is to display information about things.

What's your reaction?

Comments

https://sharpss.com/assets/images/user-avatar-s.jpg

0 comment

Write the first comment for this!