HTML <main> Tag

The HTML <main> tag represents the main content area within an HTML document.

The <main> tag surrounds the main content of the page - content that is unique to that document and is obviously the "main" content for that page. This excludes any content that is repeated across multiple pages (such as navigation bars, headers, footers, etc).

An HTML document can have more than one <main> element, but only one can be visible. If more than one <main> element is present in a document, all other instances must be hidden using the hidden attribute. Also, the <main> element must not appear within the <article>, <aside>, <footer>, <header> or <nav> tags.

The <main> tag was introduced in HTML 5.

Syntax

The <main> tag is written as <main></main> with the element's contents inserted between the start and end tags.

Like this:

Examples

Context

Here's an example of how the <main> element could be incorporated into an HTML document. This is not the only way. The <main> tag can be placed anywhere that "flow content" can be used (pretty much anywhere within the document's <body> element). However, a <main> cannot have any <article>, <aside>, <footer>, <header> or <nav> element ancestors.

Contents

The <main> element can contain "flow content", which means basically any other element that can go within the <body> element.

Here's an example of using the <main> element to represent two articles, as well as a heading and intro.

Attributes

Attributes can be added to an HTML element to provide more information about how the element should appear or behave.

The <main> element accepts the following attributes.

AttributeDescription
None 

Global Attributes

The following attributes are standard across all HTML elements. Therefore, you can use these attributes with the <main> tag , as well as with all other HTML tags.

For a full explanation of these attributes, see HTML 5 global attributes.

Event Handlers

Event handler content attributes enable you to invoke a script from within your HTML. The script is invoked when a certain "event" occurs. Each event handler content attribute deals with a different event.

Most event handler content attributes can be used on all HTML elements, but some event handlers have specific rules around when they can be used and which elements they are applicable to.

For more detail, see HTML event handler content attributes.