.

Friday, April 2, 2010

Line Breaks

Posted by devlevis | Friday, April 2, 2010 | Category: , , , , |

HTML is very forgiving of
white space—perhaps a bit too forgiving. Instead of simply
reproducing the white space contained within the code, client
browsers follow the rules of HTML, condensing white space
and only inserting formatting via tags.

For example, consider this code example:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Excerpt From Hamlet</title>
</head>
<body>
Scene I. Elsinore. A platform before the Castle.
[Francisco at his post. Enter to him Bernardo.]
Ber.
Who's there?
Fran.
Nay, answer me: stand, and unfold yourself.
Ber.
Long live the king!
Fran.
Bernardo?
Ber.
He.
Fran.
You come most carefully upon your hour.
Ber.
'Tis now struck twelve. Get thee to bed, Francisco.
Fran.
For this relief much thanks: 'tis bitter cold,
And I am sick at heart.
Ber.
Have you had quiet guard?
Fran.
Not a mouse stirring.
</body>
</html>
This text, when rendered by a browser, resembles that shown in Figure . Note how
the formatting has been completely changed due to the browser condensing all the
white space—only rendering one space where line breaks and multiple spaces appear.


This has advantages and disadvantages, linked to the following two points:
✦ You can format your code almost however you like without worrying about
affecting the formatting in the client browser.

✦ You cannot rely upon visual formatting—using multiple spaces, tabs, and line
breaks—to format your HTML documents.

Instead of using plain text, you must use HTML tags to break your document into
discrete paragraphs.

Currently have 0 comments:


Leave a Reply