HTML Guide
A main
element cannot be placed inside an article
element according to HTML5 content model rules.
The main
element is intended to identify the dominant content of the <body>
that is directly related to, or expands upon, the central topic of a document. It is meant to be unique, appearing only once per document, and must not be a descendant of elements like article
, aside
, header
, footer
, or nav
. Conversely, the article
element represents a self-contained composition that could independently be reused or distributed, such as a blog post or news story.
To resolve the error, move the main
element so that it is a direct child of the body
, and place any article
elements inside the main
or at the same level, not the other way around.
Incorrect:
<article>
<main>
<h1>Article Title</h1>
<p>This is the article content.</p>
</main>
</article>
Correct:
<main>
<article>
<h1>Article Title</h1>
<p>This is the article content.</p>
</article>
</main>
Minimal valid HTML document:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Article in Main Example</title>
</head>
<body>
<main>
<article>
<h1>Article Title</h1>
<p>This is the article content.</p>
</article>
</main>
</body>
</html>
Use only one main
element per page and ensure it is not nested inside sectioning elements such as article
.
Learn more:
Related W3C validator issues
There can only be one visible <main> element in a document. If more are needed (for example for switching between them with JavaScript), only one can be visible, the others should be hidden toggling the hidden attribute.
Example of 2 main elements, where only one is visible:
<main>
<h1>Active main element</h1>
<!-- content -->
</main>
<main hidden>
<h1>Hidden main element</h1>
<!-- content -->
</main>
The <article> element can be used to define complete, self-contained compositions of a document, for example blog posts. Consider using a heading element (any of <h2> to </h6>) to present each article.
Example:
<h1>Our blog</h1>
<article>
<h2>How to validate accessibility</h2>
<p>Use Rocket Validator for a in-depth scan</p>
</article>
<article>
<h2>How to monitor sites for accessibility</h2>
<p>Define schedules in Rocket Validator</p>
</article>
Using role="article" on a <section> element is invalid because article is not a permitted value for the role attribute.
The role attribute in HTML is used to define ARIA roles that describe the purpose of an element for assistive technologies. Only specific, predefined ARIA roles are valid per the WAI-ARIA specification. article is not a recognized ARIA role—use document or other appropriate roles instead, or omit the role attribute entirely. The <article> and <section> elements already have implicit roles, so manual role assignment is rarely necessary or useful for these elements.
Valid uses:
- Use <article> without a role attribute for content that is self-contained and intended to be independently distributable or reusable.
- Use <section> for grouping related content and omit the role attribute unless a specific ARIA landmark role is needed (such as region).
Example: use <article> for standalone content
<article>
<h2>News headline</h2>
<p>News content goes here.</p>
</article>
Example: use <section> without a role attribute for generic grouping
<section>
<h2>Introduction</h2>
<p>Section content.</p>
</section>
The role="tabpanel" attribute is not permitted on the article element according to W3C and WHATWG HTML specifications.
The role attribute helps describe the purpose of an element for assistive technologies. The value tabpanel indicates a section of a tab interface and should be used only with elements suited to that role—typically generic containers like div or section, not article. The article element has its own landmark meaning and should not be used for widgets such as tab panels.
Correct usage:
- Use role="tabpanel" on a div or section element.
- Use role="tablist" on the container of the tabs.
- Use role="tab" on each tab.
Incorrect:
<article role="tabpanel" id="panel1">
Tab panel content here.
</article>
Correct:
<div role="tabpanel" id="panel1">
Tab panel content here.
</div>
Full example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Tabpanel Example</title>
</head>
<body>
<div role="tablist">
<button role="tab" aria-controls="panel1" aria-selected="true">Tab 1</button>
<button role="tab" aria-controls="panel2" aria-selected="false">Tab 2</button>
</div>
<div role="tabpanel" id="panel1">
Tab panel content here.
</div>
<div role="tabpanel" id="panel2" hidden>
Tab panel 2 content here.
</div>
</body>
</html>
Replace the article element with a div or section when assigning the tabpanel role to ensure your markup is valid and accessible.
The article role indicates a section of a page that could easily stand on its own on a page, in a document, or on a website, is implicit when using the <article> tag.
This role indicates a section of a page that could easily stand on its own on a page, in a document, or on a website. It is usually set on related content items such as comments, forum posts, newspaper articles or other items grouped together on one page. It can be added to generic elements like <div> to convey this role, for example:
<div role="article">
<h2>Heading</h2>
<p>Content...</p>
</div>
Instead of using this role, it’s preferrable to use the native <article> element like this:
<article>
<h2>Heading</h2>
<p>Content...</p>
</article>
A main element cannot be nested within another main element.
The main element represents the primary content of a document or application, and there must be only one per page, not placed inside another main. The main element must not be used as a descendant of another main element. This is important for accessibility, semantic correctness, and helps screen readers correctly identify the main content region.
Invalid example (nested main):
<main>
<h1>Welcome</h1>
<main>
<p>This nested main element is invalid.</p>
</main>
</main>
Valid example (single main only):
<main>
<h1>Welcome</h1>
<section>
<p>This section is valid and can be placed inside main.</p>
</section>
</main>
If you need to divide the main content, use sectioning elements like section, article, or div inside a single main element, but never nest main inside main.
The main element represents the dominant contents of the document, so it should not be contained within another section.
A document must not have more than one main element that does not have the hidden attribute specified.
A hierarchically correct main element is one whose ancestor elements are limited to html, body, div, form without an accessible name, and autonomous custom elements. Each main element must be a hierarchically correct main element.
The main landmark role is used to indicate the primary content of a document. It can be added to an element by using role="main", but instead it’s preferable to just use the <main> element. In that case, it’s unnecessary to make the main role explicit. Examples:
<div role="main">
<!-- this is a valid way to define a main role -->
</div>
<main>
<!-- but this is shorter and uses correct semantic HTML -->
</main>