Skip to content

Instantly share code, notes, and snippets.

@dpheitmeyer
Last active December 4, 2015 04:17
Line Breaks and white space characters (br element)

Line Breaks and white space characters (br element)

Since "white space" characters are ignored in rendering HTML, the br element is used for explicit line breaks.

Examples below are from the first part of Paul Revere's Ride

<!DOCTYPE html>
<html>
<head>
<title>Using br for line breaks</title>
<meta charset="UTF-8"/>
</head>
<body>
<p style="background-color: #ffc">Using br for line breaks:</p>
<p>Listen, my children, and you shall hear<br/>
Of the midnight ride of Paul Revere,<br/>
On the eighteenth of April, in Seventy-Five:<br/>
Hardly a man is now alive<br/>
Who remembers that famous day and year.</p>
<p style="background-color: #ffc">Line breaks and spaces in HTML code don't render...(exception below):</p>
<p>
Listen, my children, and you shall hear
Of the midnight ride of Paul Revere,
On the eighteenth of April, in Seventy-Five:
Hardly a man is now alive
Who remembers that famous day and year.
</p>
<p style="background-color: #ffc">...except in the "pre" (preformatted) element:</p>
<pre>
Listen, my children, and you shall hear
Of the midnight ride of Paul Revere,
On the eighteenth of April, in Seventy-Five:
Hardly a man is now alive
Who remembers that famous day and year.
</pre>
<p style="background-color: #ffc">and you can use a non-break space (&#160; or &nbsp; character entities):</p>
<p>
Listen, my children, and you shall hear<br/>
   Of the midnight ride of Paul Revere,<br/>
On the eighteenth of April, in Seventy-Five:<br/>
   Hardly a man is now alive<br/>
Who remembers that famous day and year.
</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment