One thing that you'll notice is that line breaks in your HTML code aren't shown on the resulting web page. So, HTML code like this:
<p>This is line 1. This is line 2. This is line 3. </p>
would be displayed on a web page like this:
This is line 1. This is line 2. This is line 3.
which probably isn't what you want.
To get around this, you can include line breaks in your HTML code using the <br> tag:
<p>This is line 1.<br> This is line 2.<br> This is line 3.<br> </p>
The handling of spaces is similar to that of line breaks. Leading spaces and multiple spaces will be removed. Usually this is what you'd want, but there may be cases where it isn't. In that situation, you can use Non-Breaking Spaces (NBSPs).
NBSPs are the same as spaces except that text won't wrap to the next line at the point where an NBSP occurs (so the NBSP and the text before and after it will remain on the same line). Another characteristic of NBSPs is that most browsers do not remove leading NBSPs, or collapse multiple instances. However, this behavior is not guaranteed in all browsers, so you should be careful about using it.
A non-breaking space is represented by " ", as shown in the example below:
<p> This paragraph won't display the leading spaces at the start, or the multiple spaces within it.</p> <p> This paragraph will display the leading spaces at the start, and the multiple spaces within it on most browsers.</p>
Another way to overcome problems with line breaks and spaces being stripped out is to use preformatted text. This is useful if you're including things like sections of source code, because it displays exactly the way that you type it. Preformatted text is displayed in a fixed-width font, so it's not very visually-pleasing, and wouldn't be suitable for general use.
<pre>With preformatted text,
spaces and line breaks
are preserved.</pre>
<-- Previous Page Formatting Text |
Next Page --> Lists |