What's the difference between <body> and <main>? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula gr√°tis
+ 1

What's the difference between <body> and <main>?

When do I use which tag? Or are they supposed to both be used in a hierarchical form?

7th Mar 2020, 5:16 AM
Christopher Ho
Christopher Ho - avatar
4 Respostas
+ 4
The <main> tag specifies the main content of a document. The content inside the <main> element should be unique to the document. It should not contain any content that is repeated across documents such as sidebars, navigation links, copyright information, site logos, and search forms. When writing in HTML, the <body> tag is used to contain a web page's content, including hyperlinks, images, tables, text, etc. It is required in every HTML document, and there may only be one <body> tag per page.
7th Mar 2020, 5:30 AM
Rajat Porwal
+ 1
Every html element needs to have a <body> tag, but it's optional to add a <main> element. The body tag contains all your content. Whereas the main tag contains only the "main" content that you want the reader to see. The main tag is mainly (no pun intended) used for accessibility and search engine optimization purposes though. Hope this helps
8th Mar 2020, 3:41 PM
Luke Jephtha
Luke Jephtha - avatar
+ 1
Thanks! That helps clarify things a lot. For a while I thought <main> was the html5 replacement for <body> ūüėā
9th Mar 2020, 12:23 AM
Christopher Ho
Christopher Ho - avatar
0
So I should write something like.. <body> <main>... </main> </body> ?
7th Mar 2020, 6:26 AM
Christopher Ho
Christopher Ho - avatar