Forum Moderators: not2easy

Message Too Old, No Replies

Validation Question

document type does not allow element "h1" here;

         

calmseas

6:29 pm on Jan 29, 2011 (gmt 0)

10+ Year Member



The following code snippet results in the quoted validation error:
SNIPPET:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<style type="text/css">
h1 {
font-size: 2.5em ;
font-style: italic ;
color: #993300 ;
padding-left: 400px ;
padding-top: 150px ;
}

</style>
<title>About Us</title>
</head>

<body>
<div>
<p>
<h1>Who We Are</h1>
</p>
</div>
</body>
</html>

VALIDATION ERROR:
"document type does not allow element "h1" here; missing one of "object", "applet", "map", "iframe", "button", "ins", "del" start-tag
<h1>Who We Are</h1>&#9993;
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>")."

Why should the code snippet result in a validation error?

jimbeetle

7:59 pm on Jan 29, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



h element inside a p element?

alt131

2:42 pm on Jan 30, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi calmseas, as jimbeetle (and the validator) say, because you have a heading <h1> inside a para <p>.

Per the HTML recommendation:"The P element represents a paragraph. It cannot contain block-level elements..." [w3.org]

<h1> is a block-level element, so it is not allowed inside a <p>