Blog-Support

Paragraphs and Line breaks in HTML

posted Thursday, 1 February 2007

In HTML, whitespace is largely ignored. That is, as far as the browser is concerned it ignores all spaces and carriage returns inside an HTML page. We must therefore tell the browser that we want to have a paragraph break or line break by manually inserting controlling tags.

Please note, the only place whitespace is not ignored is inside tags. Tag attributes require at least one whitespace (space or carriage return) between each pair.

We have two tags that allow us to control the flow of blocks of text; Paragraph break <P>, and the line break <BR> tags.

If we had the following text inside our HTML page, it would look like:

The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.

The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.

You may be surprised to learn that when the browser renders this it will result in:

The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.

One large block of text is rendered, because the browser ignores whitespace inside the document. If we wanted to maintain the paragraph formatting we would manually encapsulate the paragraphs in the <P> ... </P> tags.

<P>
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.
</P>
<P>
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.
</P>

Which will then maintain and respect your paragraph breaks.

The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.

The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.

Always remember to close your <P> tag with a </P> at the end of the paragraph text.

The same is true for line breaks. But instead we insert the <BR> tag (which has no corresponding closer tag). For example assume we want to make sure a list was maintained we would encode:

1
<BR>2
<BR>3

Which would result in:

1
2
3

Line breaks <BR> do not have a corresponding closure tag, so you don't have to worry about that.

tags:        



Need One-to-One Help?
If you are in any doubt, contact support

Related Posts

Tag Basics

More about HTML tags including anchors and special characters

First HTML Page

Beginners HTML

Inserting mp3s or music files.

Ever thought of inserting your favorite song as an mp3 or other audio file in to your blog? Here are the instructions on how to do so.

How to add a Flash animation

Instructions on how to add a Flash animation to a blog entry, header, or custom portlet.

How do I put HTML into my blog entry?

If you are using the advanced editor, then you need to make sure you are in HTML mode before you add in HTML, do this by clicking the "html" button along the top.

Inserting images using HTML

Instructions and examples on how to insert an image using HTML. This can be used in the Basic Editor, widgets, headers, and any other fields where you can input HTML.

Paragraphs and Line breaks in HTML

How to work with paragraphs and linebreaks in HTML.

HTML Special Characters

If you need to know how to add special characters to your blog, this is your ticket!

HTML Color Reference

Hex Color codes explained.

Basic HTML

Although you can use the advanced editor some people prefer to go with the basic one. This can be tricky if you don't know much HTML. Well here we will tell you some basic HTML you can use. From making a word bold to adding images.