Is there a list of HTML5 elements that can be nested inside other elements?

Viewed 2001

I'm trying to figure out which HTML tags can be nested in other HTML tags so I can write a valid HTML 5 document for W3C and respect the flow.

Is there a list that contains for each HTML tag all the elements it can contain?

For example for the <a> tag it can contain:

TT | I | B | BIG | SMALL | EM | STRONG | DFN | CODE | SAMP | 
KBD | VAR | CITE | ABBR | ACRONYM | A | IMG | OBJECT | BR | 
SCRIPT | MAP | Q | SUB | SUP | SPAN | BDO | INPUT | SELECT | TEXTAREA | LABEL | BUTTON

I have already searched on W3C or Google but it's needed to search for each tag.

2 Answers

https://html.spec.whatwg.org/multipage/indices.html#elements-3
https://html.spec.whatwg.org/multipage/indices.html#element-content-categories

Since these helpful sections are marked as 'non-normative', technically you'd have to go to each element listing (a's, for example: https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-a-element) and check the Content model definition, which isn't always 100% straightforward, but could still probably be consumed fairly usefully programmatically.

There are pages here and there on the internet with such lists if you can't be bothered; you would just have to trust that they compiled their lists properly against the spec.

The W3C has given control of HTML5 over to the WHATWG.
https://www.w3.org/html/
http://w3.org/tr/html5

Historically (HTML5 has changed the rules on this some), inline elements can be children of most things and block elements cannot be children of inline elements, so just having an idea what is inline and what is block (block elements take up available width by default, typically forcing preceding & following elements linearly above & below), will go a long way.

you can also hav <div> inside the <a> tag and much more.

You could always read the HTML standard documentation (https://html.spec.whatwg.org/),

but as this will take a really long time I would suggest just starting to write your code, and assume that everything is possible ;)

THEN check your finished code with some Validity checker like https://validator.w3.org/

Related