0

The indentation was created by Firefox's source. Both Firefox and HTML validators said that the </p> is misplaced. But I can't figure out why.

<p>
  <ul class="errorlist">
    <li>This field is required.</li>
  </ul>
  <label for="id_creator">Creator:</label>
  <select onchange="Dajaxice.doors.orders_create_creator_changed(fill_other_fields, {&#39;creator_pk&#39;: this.options[this.selectedIndex].value})" name="creator" id="id_creator">
    <option value="" selected="selected">Select a user</option>
    <option value="9">Amy the Tenant</option>
    <option value="6">Alex the Tenant</option>
    <option value="3">Bob the Property Manager</option>
  </select>
</p>

On a side note, when Django doesn't render the error messages, then the closing </p> tag is valid. Here is the code:

<p>
  <label for="id_creator">Creator:</label>
  <select onchange="Dajaxice.doors.orders_create_creator_changed(fill_other_fields, {&#39;creator_pk&#39;: this.options[this.selectedIndex].value})" name="creator" id="id_creator">
    <option value="" selected="selected">Select a user</option>
    <option value="9">Amy the Tenant</option>
    <option value="6">Alex the Tenant</option>
    <option value="3">Bob the Property Manager</option>
  </select>
</p>
TylerH
  • 20,799
  • 66
  • 75
  • 101
hobbes3
  • 28,078
  • 24
  • 87
  • 116

2 Answers2

3

<p> can't include any block-level elements (see MDN docu).

<ul> on the other hand is an block level element (MDN).

The reason your code might be displayed "correctly" is that most html5 parsers insert a closing </p> when they encounter a block level element inside a <p>. With this being inserted your actual </p> has no accompanying opening <p> and in consequence is not valid at that point.

Sirko
  • 72,589
  • 19
  • 149
  • 183
  • The reason his code displays correctly is because browsers try very hard to deal with malformed and invalid HTML. That doesn't make it correct or valid. – Madara's Ghost Apr 21 '12 at 09:33
  • @Truth Accoding to [this](http://www.w3.org/TR/html-markup/p.html) The insertion of the `` tag is standard conform (we could discuss the cleanness of the code, though). So following this the closing `` without any opening tag can be seen as invalid markup, whereas the rest is standard conform. – Sirko Apr 21 '12 at 09:36
  • @Sirko: Closing the `` element is always valid (assuming one was opened). It's optional to omit the closing tag if it is followed by one of the following elements: address, article, aside, blockquote, dir, div, dl, fieldset, footer, form, h1, h2, h3, h4, h5, h6, header, hr, menu, nav, ol, p, pre, section, table, or ul. – Madara's Ghost Apr 21 '12 at 09:39
  • 1
    @Truth I think you didn't get my point. From a parsers perspective the code is perfectly valid until it gets to the ``. This is the first (only?) invalid tag in that code (from the parsers simple point of view). From the developer's point of view the `
      ` is misplaced here.
    – Sirko Apr 21 '12 at 09:42
1

an <ul /> is block level so it can't be held inside a <p />

Stuart Burrows
  • 10,824
  • 2
  • 34
  • 33