You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Warn if there is more than one main HTML element, or if the main is missing #35354
A few blocks have an option to change the HTML element to <main>, but there must only be one main element on a page.
Having more than one <main> element (that is not hidden) is invalid HTML and an accessibility issue.
What is your proposed solution?
Add a warning if there is more than one main element -perhaps in the document outline "table of content" details popover?
It already warns for incorrect heading levels.
Reacted by Will Skora, George Mamadashvili, Ari Stathopoulos, Damon Cook and Birgit Pauli-Haack
A document mustn't have more than one <main> element that doesn't have the hidden attribute specified.
It is possible to have more than one main, but only one that's not hidden. Right now I don't believe we add hidden anywhere, but any check we add should take the hidden scenario into account. 👍
changed the title [-]Warn if there is more than one main HTML element[/-][+]Warn if there is more than one main HTML element, or if the main is missing[/+]on Jul 19, 2024
The accessibility features "Skip to content" + <main/> section could use the attention similar to the color low contrast warning, when selecting text and background colors.
A user can so easily remove a <main/> section tag by just removing a root group block. This came up in two discussions in the #outreach channel as well,
Apart from the warning, and update on documentation would also be beneficial to add the HTML Element selector to other blocks, like post content, media+text when used in a template context.
I think there are performance issues with looping through all blocks on the current page, find blocks that use the tagName attribute, and then check if that tagName is main. The check for the heading level is much more limited because it only checks the heading block.
The check should be limited to block themes, because the editor does not know what other tags there are in classic theme templates. (*To do, check if the heading outline is available on classic themes and if it is accurate).
The check may need to be limited to the Site Editor, unless it can check both template and block editor contents.
A new help text needs to be written, explaining why the main is needed.
A link to more information should be added, similar to the link added to the alt text help.
I've recently worked on a solution where I've implemented this via a block theme itself and it's working fine. Here's how it looks:
It's only available in the site editor and on templates (not template parts, patterns and pages). It recursively checks the content with wp.data.select( 'core/editor' ).getEditorBlocks(). The message changes if there's no main tag found or if there's more than one main tag found and it also displays how many tags were found, however not where specifically.
I like that the message shows as a notice this way and not as a warning in the Document Outline panel where it would be less visible.
+1
This will be especially helpful for theme developers working on implementing zoom-out functionality. While building TT5 and working with templates that include nested groups, we encountered some challenges.
We have since improved the warning in the Greyd Theme, the update still has to be rolled out to the Greyd WP theme but I agree, it's confusing when you just have the message without knowing where to look for the main tag.
Recently, I (re)discovered a proposal from #41747 to allow displaying errors/warnings in the list. Now I think it might be a more suitable place for displaying similar warnings.
The problem is that still going to be that if you have more than one block that can use the main element, where in list view do you show the message that there is no main element in the document?
We can't show it when any or multiple of those elements are selected or expanded. As mentioned in the PR that will just confuse the user about where to add it, and they may add it randomly to any of these elements which would be an accessibility problem.
We can't tie a document level warning to a single block.
As far as I understand, #41747 proposes a dropdown where errors and warnings can be displayed. So it will be no different from displaying a warning in a Document Overview.
In any case, this won't be a blocker for #68661, I just remembered an old issue and wanted to connect some dots.
I'll try to move the current proposal forward. I should have time for it this week.
Activity
aristath commentedon Oct 6, 2021
Note from the MDN Docs:
It is possible to have more than one
main, but only one that's nothidden. Right now I don't believe we addhiddenanywhere, but any check we add should take thehiddenscenario into account. 👍carolinan commentedon Oct 25, 2021
[-]Warn if there is more than one main HTML element[/-][+]Warn if there is more than one main HTML element, or if the main is missing[/+]bph commentedon Aug 2, 2024
The accessibility features "Skip to content" +
<main/>section could use the attention similar to the color low contrast warning, when selecting text and background colors.A user can so easily remove a
<main/>section tag by just removing a root group block. This came up in two discussions in the #outreach channel as well,Apart from the warning, and update on documentation would also be beneficial to add the HTML Element selector to other blocks, like post content, media+text when used in a template context.
@WordPress/outreach
carolinan commentedon Aug 3, 2024
Some thoughts:
mainis needed.luminuu commentedon Aug 5, 2024
I've recently worked on a solution where I've implemented this via a block theme itself and it's working fine. Here's how it looks:

It's only available in the site editor and on templates (not template parts, patterns and pages). It recursively checks the content with
wp.data.select( 'core/editor' ).getEditorBlocks(). The message changes if there's no main tag found or if there's more than one main tag found and it also displays how many tags were found, however not where specifically.getdave commentedon Dec 2, 2024
Related to #65400. Soon Zoom Out will not be available if
<main>does not exist. Therefore it would be great if there could be a warning about:<main><main>getdave commentedon Dec 2, 2024
@luminuu Looks great, would you be open to raising a PR with your code? 🙏
carolinan commentedon Dec 2, 2024
I like that the message shows as a notice this way and not as a warning in the Document Outline panel where it would be less visible.
juanfra commentedon Dec 2, 2024
+1
This will be especially helpful for theme developers working on implementing zoom-out functionality. While building TT5 and working with templates that include nested groups, we encountered some challenges.
luminuu commentedon Dec 5, 2024
@getdave The code is specific to a theme, I assume it has to be rewritten in order to land in core? The code can be found here: https://github.com/Greyd-Suite/greyd-wp/blob/main/assets/js/editor-main-tag-warning.js
carolinan commentedon Jan 14, 2025
I have made some progress on this, but I am wondering how to best explain to the user how to act on the warning:
Perhaps the notice needs an external link to a support page?
I think the warning would be easier to act on, if it was clearer in the list view which groups already have the
<main>tag:#42610
luminuu commentedon Jan 24, 2025
We have since improved the warning in the Greyd Theme, the update still has to be rolled out to the Greyd WP theme but I agree, it's confusing when you just have the message without knowing where to look for the main tag.
Thank you for working on this @carolinan!
Mamaduka commentedon Jul 16, 2025
Recently, I (re)discovered a proposal from #41747 to allow displaying errors/warnings in the list. Now I think it might be a more suitable place for displaying similar warnings.
carolinan commentedon Jul 16, 2025
The problem is that still going to be that if you have more than one block that can use the main element, where in list view do you show the message that there is no main element in the document?
We can't show it when any or multiple of those elements are selected or expanded. As mentioned in the PR that will just confuse the user about where to add it, and they may add it randomly to any of these elements which would be an accessibility problem.
We can't tie a document level warning to a single block.
Mamaduka commentedon Jul 16, 2025
As far as I understand, #41747 proposes a dropdown where errors and warnings can be displayed. So it will be no different from displaying a warning in a Document Overview.
In any case, this won't be a blocker for #68661, I just remembered an old issue and wanted to connect some dots.
I'll try to move the current proposal forward. I should have time for it this week.