Skip to main content
Updated the links to the W3C Specs. I checked against the 2016-02-07 archived versions on archive.org - the day when Oriol created the answer.
Source Link

According to HTML5, the content modelcontent model of divdiv elements is flow contentflow content

Most elements that are used in the body of documents and applications are categorized as flow content.

That includes pp elements, which can only be usedcan only be used where flow contentflow content is expected.

Therefore, div elements can contain p elements.


However, the content modelcontent model of pp elements is Phrasing contentPhrasing content

Phrasing content is the text of the document, as well as elements that mark up that text at the intra-paragraph level. Runs of phrasing contentphrasing content form paragraphsparagraphs.

That doesn't include divdiv elements, which can only be usedcan only be used where flow contentflow content is expected.

Therefore, p elements can't contain div elements.

Since the end tagend tag of pp elements can be omitted when the p element is immediately followed by a div element (among others), the following

<p>
  <div>some words</div>
</p>

is parsed as

<p></p>
<div>some words</div>
</p>

and the last </p> is an error.

According to HTML5, the content model of div elements is flow content

Most elements that are used in the body of documents and applications are categorized as flow content.

That includes p elements, which can only be used where flow content is expected.

Therefore, div elements can contain p elements.


However, the content model of p elements is Phrasing content

Phrasing content is the text of the document, as well as elements that mark up that text at the intra-paragraph level. Runs of phrasing content form paragraphs.

That doesn't include div elements, which can only be used where flow content is expected.

Therefore, p elements can't contain div elements.

Since the end tag of p elements can be omitted when the p element is immediately followed by a div element (among others), the following

<p>
  <div>some words</div>
</p>

is parsed as

<p></p>
<div>some words</div>
</p>

and the last </p> is an error.

According to HTML5, the content model of div elements is flow content

Most elements that are used in the body of documents and applications are categorized as flow content.

That includes p elements, which can only be used where flow content is expected.

Therefore, div elements can contain p elements.


However, the content model of p elements is Phrasing content

Phrasing content is the text of the document, as well as elements that mark up that text at the intra-paragraph level. Runs of phrasing content form paragraphs.

That doesn't include div elements, which can only be used where flow content is expected.

Therefore, p elements can't contain div elements.

Since the end tag of p elements can be omitted when the p element is immediately followed by a div element (among others), the following

<p>
  <div>some words</div>
</p>

is parsed as

<p></p>
<div>some words</div>
</p>

and the last </p> is an error.

Source Link
Oriol
  • 283.7k
  • 66
  • 453
  • 526

According to HTML5, the content model of div elements is flow content

Most elements that are used in the body of documents and applications are categorized as flow content.

That includes p elements, which can only be used where flow content is expected.

Therefore, div elements can contain p elements.


However, the content model of p elements is Phrasing content

Phrasing content is the text of the document, as well as elements that mark up that text at the intra-paragraph level. Runs of phrasing content form paragraphs.

That doesn't include div elements, which can only be used where flow content is expected.

Therefore, p elements can't contain div elements.

Since the end tag of p elements can be omitted when the p element is immediately followed by a div element (among others), the following

<p>
  <div>some words</div>
</p>

is parsed as

<p></p>
<div>some words</div>
</p>

and the last </p> is an error.