News & UpdatesProgrammingWeb programming Store My Projects
Links
Affiliates

HTML Tutorial – 04 – Whitespace

In HTML, all kinds of whitespace characters are ignored. This means the page will render the same no matter how it is formatted and the text will contain no line breaks except for when it wraps around the edge of the screen. To override this behavior there are several elements available.

Break tag

First, there is the break tag that forcibly breaks a line of text and creates a newline.

<br>

Paragraph element

A similar element is the paragraph, which adds more vertical space than the break tag. Its end tag is optional.

<p>...</p>

The paragraph can be aligned using the align attribute. Valid values for this attribute are left, right, center and justify.

<p align="center">...</p>

Preformatted element

Whitespace can be preserved using the preformatted element. Within this element the text will appear exactly as it is typed and it will be rendered with a fixed-width typeface.

<pre>...</pre>

When trying to add more than one space character in a row these spaces will be collapsed. To force spacing a non-breaking space (&nbsp;) can be used. This character cannot be typed directly from the keyboard. Instead, it is referenced with a notation that starts with an ampersand and end with a semicolon. This notation is used to type characters that have special meaning.

&nbsp;

Some other important special characters are: &lt; (<), &gt; (>) and &amp; (&).

Comments

There is a special kind of tag used only to include comments. This tag may span multiple lines and can appear anywhere in the document.

<!-- This is an HTML comment -->
Recommended additional reading:
Sams - Teach Yourself HTML and CSS in 24 Hours