White Space

Standard Handling

Spaces, tabs, and new lines (white space) in the source code are collapsed down to a single space. As an example:

<p>   This is     [tab]		a test


imonial.</p>

Displays as:
This is a test imonial.

You can see that the new lines were converted to a single space. If you don’t want white space to collapse you can use the <pre> tag. With CSS3, we have a lot more options for controlling line breaks and spaces. See below...

New line with <wbr> (word break)

The <wbr> tag will give the browser a hint where it can break a very long set of words with no spaces in it. By adding <wbr> you can define logical areas where the text can start a new line.

window.open('myPage.html','windowName','scrollbars=yes,resizable=yes,width=1054,height=783');

The above line uses the code:

window.open('myPage.html',<wbr>'windowName',<wbr>'scrollbars=yes,<wbr>resizable=yes,<wbr>width=1054,<wbr>height=783');

Warning: IE8 will ignore <wbr> when running in standards-mode. The work around is to use a zero-width space instead.

Non-breaking Spaces with &nbsp;

Multiple white space characters (spaces and line breaks) will normally collapse down to a single space. If you would like multiple spaces, for example two spaces between sentences, then use &nbsp; in your code. The easiest way to get it is with the keyboard shortcut: Command Shift Space.

Go there.  Now.

<p>Go there. &nbsp;Now.</p>

CSS Properties

Stephen Morley has done a great job of explaining this topic.

http://code.stephenmorley.org/html-and-css/white-space-handling/

The CSS2 properties/values related to white space are:

white-space: normal | pre | nowrap | pre-wrap | pre-line