Formatting Text in HTML

What HTML ignores

If you've tried writing some HTML already then you've probably noticed that it doesn't pay much attention to how you format the text. All of the formatting in HTML is done with tags. Because of this, formatting the text does nothing. Here are some examples of what HTML doesn't do:

What this means is that all but single spaces get ignored, and it doesn't matter how a line ends.

How to format text in HTML

Now that you know what HTML ignores, you're probably wondering how to format your text in HTML. You have to use tags to do this. This is an advantage though because then it doesn't matter how big the text is when a person looks at the page, the browser takes care of that. Because the text could be displayed wider or narrower, bigger or smaller by different machines this lets you not have to worry about that. The same paragraph could be a very different length on 2 different browsers because one of them might display the text in a bigger window, but both would look right.

The first formatting tag is the <p> tag. Normally this tag is does not need a </p> to close it, as soon as the browser sees another <p> tag (or any other tag that starts a new line) it is assumed that the last one has ended. This tag is the paragraph tag, and is probably the tag you will use the most if you put a lot of text on your pages. It tells the browser that the text is to be formatted like a paragraph. What this means is that the browser will put in a blank line and then start to display the text, wrapping to new lines as needed. When the next <p> tag comes up the browser puts another blank line and then does the text that follows that tag.

If you want to end one line but not put in a blank line like this:
First line
Second line
Then you need to use the <br> tag, the break tag. All that this does is end the line you are on.

The <br> tag is also useful if you want to make multiple blank lines. You can't do this with multiple <p> tags, they just collapse into one blank line. Instead, you use <br>, first put a <br> tag at the end of the line you're on, then put a <br> tag for each blank line you want.

Aligning text

You now know how to format paragraphs but what if you don't want the text to look just like a normal paragraph? What if you want something just on the right side, or centered? To do this you use the align attribute. An attribute is additional information that you can put into a tag. The <p> tag can accept many attributes (most of which are experimental and so are not well supported), including the align attribute. To use any attribute you just put it into the tag:
<p align="center">text</p>
Note that here you have to put in a </p> tag to close the paragraph, this is so that the browser is certain where the special formatting ends. You can use this to align the text left, right, or center.

Netscape has also created a <center> tag which you may have seen. This tag is a newer tag and so not all browsers will support it, it is safer to use the align attribute instead.


Related Help Topics Search the Helpdesk Contacts (Support) Recent Changes VTN Home Page