Home Web Front-end CSS Tutorial Can a `` Element Be a Direct Child of a `` Element in HTML?

Can a `` Element Be a Direct Child of a `` Element in HTML?

Dec 22, 2024 am 04:33 AM

Can a `` Element Be a Direct Child of a `` Element in HTML?

Div as a Direct Child of UL: A Careful Approach

In HTML, it's commonly believed that only the

  • element can be a direct child of the
      element. However, some sources seem to suggest that
      can also be a valid child in certain circumstances. This discrepancy has led to confusion among developers.

      HTML 4 and 5 Specifications

      Let's examine the HTML 4 and 5 specifications to clarify this issue.

      • HTML 4: The content model for

          explicitly states that it can only contain
        • elements:

          <!ELEMENT UL - - (LI) +      -- unordered list -- >
          Copy after login
        • HTML 5: The content model for

            similarly specifies only
          • elements:

            Content model:
            Zero or more li elements.
            Copy after login

          Interpretation

          The content model specifications clearly indicate that the only valid child of