Where can I find a list of proper HTML nesting sta

2019-06-11 20:51发布

问题:

I've been crawling Stack Overflow and the rest of the web, looking for proper nesting standards in regards to all HTML elements, but the search seems to be in vain.

Which is why I am asking, where is there a reference of the proper nesting standards (such as the fact that you can't put <div> tags inside a <p> tag)?

回答1:

Try the language definition

(hint: there are indexen of elements and attributes if you scroll down to the bottom)

EDIT: there's also the latest draft of HTML5



回答2:

In HTML5, each element has

  • a list of categories it belongs to, and
  • a content model.

The content model describes (with the help of categories) the expected contents of an element (e.g., which elements are allowed as children). See Elements → Content models for a list of the categories.

Example: The p element is defined as:

Categories:

  • Flow content.
  • Palpable content.

Content model:

  • Phrasing content.

So p can contain any element that belongs to the "phrasing content" category (a, abbr, …).

And p can be child of any element whose content model expects "flow content" and/or "palpable content". (For convenience, "contexts in which this element can be used" describes those elements (but it’s non-normative).)


Note that other specifications may modify the definitions. For example, RDFa and Microdata extend HTML5 to allow meta/link in the body.