I’ve seen bits of information here and there about elements that are valid children of other elements. For example <tr>
cannot be a child of <span>
, etc. Is there a resource that provides an exhaustive list/table of what parent/child relationships are allowed in the DOM? Thanks!
2
Answers
Yes, but not in a table format. Both the HTML spec and MDN’s reference doc list what each sort of element can be a parent/child of.
Yes, there is an exhaustive list of what elements can be children of what elements in HTML5. The HTML5 specification defines the rules for the structure of an HTML document, including the allowed parent-child relationships between elements.
The rules can be complex, but generally, each HTML element has a set of allowed parent elements and a set of allowed child elements. These relationships are defined in the HTML5 specification and can be found in the element reference section.
To find the allowed parent and child elements for a specific element, you can look up the element in the HTML5 specification, or use resources like the Mozilla Developer Network (MDN) web documentation or the W3Schools website.
However, it’s worth noting that HTML5 is designed to be forgiving and to handle a wide range of document structures. As such, in practice, many elements can be nested in unexpected ways and still work in most modern web browsers.