Home > Enterprise >  In HTML, should the main tag be wrapped inside the body tag?
In HTML, should the main tag be wrapped inside the body tag?

Time:10-02

Beginner here. In HTML, should the main tag always be nested inside the body tag?

Is there any difference/impact between below two?

<body></body>
<main></main>

<body><main></main></body>

CodePudding user response:

The first example is completely invalid. The second is correct. Your content must be within the body of the document.

CodePudding user response:

The <main></main> tag can only be used once per page, it represents the central topic or core content of the document body and is considered an HTML 5 block element.

The second is valid

<body>
<main>

</main>
</body>

CodePudding user response:

The first sentence of the [MDN page on <main>] states

The <main> HTML element represents the dominant content of the <body> of a document.

So <main> is intended to be used as a part of <body>, hence within it.

  •  Tags:  
  • html
  • Related