2.8 Whitespace Collapsing

The next block element we’ll describe is the pre element. But for the pre element to make sense, we first need to explain whitespace collapsing. Whitespace refers to characters that are invisible when displayed on the browser window. The most common whitespace characters are the blank, newline, and tab characters. The web developer generates those characteristics by pressing the spacebar, enter, and tab keys, respectively. Normally, browsers collapse whitespace. In other words, if your HTML code contains consecutive blank spaces, newlines, or tabs, the browser will display the web page with only one whitespace character (usually a blank space).

For an example of whitespace collapsing, let’s look at a haiku web page. ...

Get Web Programming with HTML5, CSS, and JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.