HTML main Tag
The <main>
tag is an HTML element introduced in HTML5 that represents the main content of an HTML document. It is used to mark the primary content area of a web page, excluding headers, footers, sidebars, and other peripheral content.
Here’s an example of how the <main>
tag is used:
<body>
<header>
<!-- Header content -->
</header>
<main>
<!-- Main content of the page -->
<h1>Welcome to My Website</h1>
<p>This is the main content area.</p>
<!-- Additional content -->
</main>
<footer>
<!-- Footer content -->
</footer>
</body>
In this example, the <main>
tag is used to encapsulate the primary content of the web page. It typically contains the core information, articles, sections, or any other significant content that defines the purpose of the page.
The <main>
tag serves several purposes:
1. Accessibility: It helps assistive technologies understand and navigate the main content area of the page more easily. Screen readers, for example, can jump directly to the main content when encountering the <main>
tag.
2. Document Structure: It improves the structure and semantics of the HTML document, making it easier to understand and maintain.
3. Styling and Layout: It allows targeted styling and layout adjustments for the main content area using CSS. You can apply specific styles or define a layout grid for the <main>
element.
It’s important to note that an HTML document should contain only one <main>
element, and it should not be nested within other <main>
elements. It should also be a direct child of the <body>
element.
If the main content of your page is divided into distinct sections, you can still use appropriate sectioning elements such as <article>
, <section>
, or <div>
within the <main>
element to further structure and organize the content.
Overall, using the <main>
tag helps improve the accessibility, structure, and styling capabilities of your web pages by explicitly defining the primary content area.