View Full Version : Invalid line break?

12-11-2006, 10:31 PM
When I attempt to validate my code with XHTML strict, I receive errors on line breaks and I am not sure why. I have been using <br /> with XHTML transitional for the longest time with no problems and I am certain that I have used it in the past with a strict doctype.

This is the error I am receiving:

Error Line 77 column 5: document type does not allow element "br" here; missing one of "p", "h1", "h2", "h3", "h4", "h5", "h6", "div", "pre", "address", "fieldset", "ins", "del" start-tag.

<br />

The mentioned element is not allowed to appear in the context in which you've placed it; the other mentioned elements are the only ones that are both allowed there and can contain the element mentioned. This might mean that you need a containing element, or possibly that you've forgotten to close a previous element.

One possible cause for this message is that you have attempted to put a block-level element (such as "<p>" or "<table>") inside an inline element (such as "<a>", "<span>", or "<font>").

I think that there must be something else wrong with my code, but I cannot find it. Can anyone tell me why I am getting this error with <br />?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<!-- all html written by Dorienne Smith -->
<link rel="shortcut icon" href="favicon.ico" />
<link rel="stylesheet" href="home.css" type="text/css" />

<meta name="keywords" content="dorienne smith, calvin and hobbes, calvin, hobbes, bill watterson, comics, downloads, pictures, images, gifs, books, facts, poetry" />
<meta name="description" content="Midnight Calvin - For those whose midnight pastime is re-discovering the beloved comic Calvin and Hobbes" />
<meta name="owner" content="kaitco@doriennesmith.com" />
<meta name="author" content="Dorienne Smith" />
<meta http-equiv="content-language" content="English" />
<meta name="rating" content="General" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Poetry - Midnight Calvin -- Dorienne Smith.com</title>

<style type="text/css">
html, body {
color: #fff;
background: #000;
font-family: Arial, Helvetica, sans-serif;
font-size: 18px;

a {
color: #fff;

a img {
border-style: none;

ul {
list-style: none;
font-size: 12px;
text-align: center;

li {
display: inline;

h1 {
text-align: center;

dl {
padding: 1em 0;

dt {
font: normal large Verdana, Arial, Helvetica, sans-serif;

dd {
font: normal small Tahoma, Arial, Helvetica, sans-serif;

p {
font: medium, Arial, Helvetica, sans-serif;
padding: 0;
margin: 0;

#footer {
text-align: center;


<?php include ("nav.php"); ?>
<h1><a id="top"><img src="images/players/newpoetry.gif" alt="Poetry" /></a></h1>
<br />
<li><a href="#alien">Alien Brain Drain</a></li>
<li><a href="#mind">Exploring Mind</a></li>
<li><a href="#mum">My Mom and Dad</a></li>
<li><a href="#night">Nauseous Nocturne</a></li>
<li><a href="#sixmas">Six Days 'Til Christmas</a></li>
<li><a href="#trex">The Tyrannosaur</a></li>
<li><a href="#water">Water-Stealing Blue Collar Work</a></li>
<li><a href="#eve">Christmas Eve</a></li>

<dt><a id="alien">Alien</a> Brain Drain</dt>
<dd>While lying on my back to make</dd>
<dd>An angel in the snow</dd>
<dd>I saw a greenish graft appear!</dd>
<dd>A giant UFO!</dd>
<dd>A strange, unearthly hum it made!</dd>
<dd>It hovered overhead!</dd>
<dd>And aliens were moving 'round</dd>
<dd>In view ports glowing red!</dd>
<dd>I tried to run for cover, but</dd>
<dd>A hook that they had low'r'd</dd>
<dd>Snagged me by my overcoat</dd>
<dd>And hoisted me aboard.</dd>
<dd>Even then, I tried to fight</dd>
<dd>And though they numbered many,</dd>
<dd>I poked them in their compound eyes</dd>
<dd>And pulled on their antennae!</dd>
<dd>It was no use! They dragged me to </dd>
<dd>A platform, tied me up,</dd>
<dd>And wired to my cranium</dd>
<dd>A fiendish suction cup!</dd>
<dd>They turned it on and current coursed</dd>
<dd>Across my cerebellum</dd>
<dd>Coaxing from my brain tissue</dd>
<dd>The things I wouldn't tell 'em!</dd>
<dd>All the math I ever learned,</dd>
<dd>The numbers and equations,</dd>
<dd>Were mechanic'ly removed in this</dd>
<dd>Brain-draining operation!</dd>
<dd>My escape was an adventure.</dd>
<dd>(I won't tell you what I did.)</dd>
<dd>Suffice to say, I cannot add,</dd>
<dd>So ask some other kid.</dd>
<p>Back to the <a href="#top">top</a></p>
<div id="footer">
<p><a href="calvinbuy.php"><img src="images/newcalbuy.gif" alt="Buy Calvin and Hobbes" /></a></p>
<?php include ("bar.php"); ?>
<p><img src="/cgi-sys/Count.cgi?df=calvin.dat|display=Counter|ft=6|md=5|frgb=100;139;216|dd=C" alt="counter" /></p>


12-11-2006, 10:52 PM
What the error message is basically saying is that you can't have a <br /> tag out by itself, it needs to be inside one of the tags listed in the first sentence of the error message.

The usage you are using might be allowed under a transitional doc type so that might be why you haven't really ran into this problem before.

12-11-2006, 10:58 PM
Wow! I never knew a line break could not stand by itself. I guess you learn something new everyday. Thanks! :)

12-11-2006, 11:45 PM
Though I don't think you are using the break return properly. In the way you are using it you should be using a bottom margin on the h1 tag before it instead.

12-12-2006, 12:24 AM
Yeah, I know it is better to just change the margins to get the effect that was created by the line break, but I wanted to know what the problem was and in the process learned how <br /> should and should not be used.