-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Restrict the main element to be used once per document #3354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2c570b9
Restrict the main element to be used once per document
annevk 38465fa
nit
annevk 8f1b75f
only allow main in body/div
annevk 701e6bc
zero or more
annevk 433ec9c
it's actually more complicated
annevk be4c49d
attempt at defining the restrictions in terms of ancestors (similar t…
annevk cac0c21
simplify requirement
annevk 8460af5
ack Alice Wonder
annevk 783612c
nits
annevk 0bc0404
tiny nit
annevk 5050f0f
main element ancestors abstraction didn't work on closer inspection
annevk 8200648
add accessible name restrictions to form
annevk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10698,7 +10698,7 @@ console.assert(image.height === 200);</pre> | |
| <li><code>kbd</code></li> | ||
| <li><code>label</code></li> | ||
| <li><code>link</code> (if it is <span>allowed in the body</span>)</li> | ||
| <li><code>main</code></li> | ||
| <li><code>main</code> (if it is a <span>hierarchically correct <code>main</code> element</span>)</li> | ||
| <li><code>map</code></li> | ||
| <li><code>mark</code></li> | ||
| <li><span>MathML <code>math</code></span></li> | ||
|
|
@@ -15172,7 +15172,7 @@ interface <dfn>HTMLBodyElement</dfn> : <span>HTMLElement</span> {}; | |
| <dd w-nohtml>Uses <code>HTMLBodyElement</code>.</dd> | ||
| </dl> | ||
|
|
||
| <p>The <code>body</code> element <span>represents</span> the main content of the document.</p> | ||
| <p>The <code>body</code> element <span>represents</span> the contents of the document.</p> | ||
|
|
||
| <p>In conforming documents, there is only one <code>body</code> element. The <code | ||
| data-x="dom-document-body">document.body</code> IDL attribute provides scripts with easy access to | ||
|
|
@@ -15552,7 +15552,7 @@ interface <dfn>HTMLBodyElement</dfn> : <span>HTMLElement</span> {}; | |
| <dt><span data-x="concept-element-contexts">Contexts in which this element can be used</span>:</dt> | ||
| <dd>Where <span>flow content</span> is expected.</dd> | ||
| <dt><span data-x="concept-element-content-model">Content model</span>:</dt> | ||
| <dd><span>Flow content</span>, but with no <code>main</code> element descendants.</dd> | ||
| <dd><span>Flow content</span>.</dd> | ||
| <dt><span data-x="concept-element-attributes">Content attributes</span>:</dt> | ||
| <dd><span>Global attributes</span></dd> | ||
| <dt><span data-x="concept-element-dom">DOM interface</span>:</dt> | ||
|
|
@@ -15729,7 +15729,7 @@ interface <dfn>HTMLBodyElement</dfn> : <span>HTMLElement</span> {}; | |
| <dt><span data-x="concept-element-contexts">Contexts in which this element can be used</span>:</dt> | ||
| <dd>Where <span>flow content</span> is expected.</dd> | ||
| <dt><span data-x="concept-element-content-model">Content model</span>:</dt> | ||
| <dd><span>Flow content</span>, but with no <code>main</code> element descendants.</dd> | ||
| <dd><span>Flow content</span>.</dd> | ||
| <dt><span data-x="concept-element-attributes">Content attributes</span>:</dt> | ||
| <dd><span>Global attributes</span></dd> | ||
| <dt><span data-x="concept-element-dom">DOM interface</span>:</dt> | ||
|
|
@@ -16118,7 +16118,8 @@ Space is not the only void</pre> | |
| <dt><span data-x="concept-element-contexts">Contexts in which this element can be used</span>:</dt> | ||
| <dd>Where <span>flow content</span> is expected.</dd> | ||
| <dt><span data-x="concept-element-content-model">Content model</span>:</dt> | ||
| <dd><span>Flow content</span>, but with no <code>header</code>, <code>footer</code>, or <code>main</code> element descendants.</dd> | ||
| <dd><span>Flow content</span>, but with no <code>header</code> or <code>footer</code> element | ||
| descendants.</dd> | ||
| <dt><span data-x="concept-element-attributes">Content attributes</span>:</dt> | ||
| <dd><span>Global attributes</span></dd> | ||
| <dt><span data-x="concept-element-dom">DOM interface</span>:</dt> | ||
|
|
@@ -16204,7 +16205,8 @@ Space is not the only void</pre> | |
| <dt><span data-x="concept-element-contexts">Contexts in which this element can be used</span>:</dt> | ||
| <dd>Where <span>flow content</span> is expected.</dd> | ||
| <dt><span data-x="concept-element-content-model">Content model</span>:</dt> | ||
| <dd><span>Flow content</span>, but with no <code>header</code>, <code>footer</code>, or <code>main</code> element descendants.</dd> | ||
| <dd><span>Flow content</span>, but with no <code>header</code> or <code>footer</code> element | ||
| descendants.</dd> | ||
| <dt><span data-x="concept-element-attributes">Content attributes</span>:</dt> | ||
| <dd><span>Global attributes</span></dd> | ||
| <dt><span data-x="concept-element-dom">DOM interface</span>:</dt> | ||
|
|
@@ -18962,9 +18964,9 @@ first matching case):</p> | |
| <dt><span data-x="concept-element-contexts">Contexts in which this element can be used</span>:</dt> | ||
| <dd>Where <span>flow content</span> is expected.</dd> | ||
| <dt><span data-x="concept-element-content-model">Content model</span>:</dt> | ||
| <dd>Either: One <code>figcaption</code> element followed by <span>flow content</span>.</dd> | ||
| <dd>Or: <span>Flow content</span> followed by one <code>figcaption</code> element.</dd> | ||
| <dd>Or: <span>Flow content</span>.</dd> | ||
| <dd>Either: one <code>figcaption</code> element followed by <span>flow content</span>.</dd> | ||
| <dd>Or: <span>flow content</span> followed by one <code>figcaption</code> element.</dd> | ||
| <dd>Or: <span>flow content</span>.</dd> | ||
| <dt><span data-x="concept-element-attributes">Content attributes</span>:</dt> | ||
| <dd><span>Global attributes</span></dd> | ||
| <dt><span data-x="concept-element-dom">DOM interface</span>:</dt> | ||
|
|
@@ -19188,7 +19190,8 @@ included with Exhibit B. | |
| <dd><span>Flow content</span>.</dd> | ||
| <dd><span>Palpable content</span>.</dd> | ||
| <dt><span data-x="concept-element-contexts">Contexts in which this element can be used</span>:</dt> | ||
| <dd>Where <span>flow content</span> is expected.</dd> | ||
| <dd>Where <span>flow content</span> is expected, but only if it is a <span>hierarchically correct | ||
| <code>main</code> element</span>.</dd> | ||
| <dt><span data-x="concept-element-content-model">Content model</span>:</dt> | ||
| <dd><span>Flow content</span>.</dd> | ||
| <dt><span data-x="concept-element-attributes">Content attributes</span>:</dt> | ||
|
|
@@ -19197,15 +19200,17 @@ included with Exhibit B. | |
| <dd>Uses <code>HTMLElement</code>.</dd> | ||
| </dl> | ||
|
|
||
| <p>The <code>main</code> element can be used as a container for the dominant contents of the | ||
| document. It <span>represents</span> its children.</p> | ||
| <p>The <code>main</code> element <span>represents</span> the dominant contents of the | ||
| document.</p> | ||
|
|
||
| <p class="note">The <code>main</code> element is distinct from the <code>section</code> and | ||
| <code>article</code> elements in that the <code>main</code> element does not contribute to the | ||
| document <span>outline</span>.</p> | ||
| <p>A document must not have more than one <code>main</code> element that does not have the <code | ||
| data-x="attr-hidden">hidden</code> attribute specified.</p> | ||
|
|
||
| <p class="note">While there is no restriction as to the number of <code>main</code> elements in a | ||
| document, web developers are encouraged to stick to a single element.</p> | ||
| <p>A <dfn>hierarchically correct <code>main</code> element</dfn> is one whose ancestor elements | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is great, simplified a lot of the other bits. Thanks! |
||
| are limited to <code>html</code>, <code>body</code>, <code>div</code>, <code>form</code> without | ||
| an <span data-x="concept-accessible-name">accessible name</span>, and <span data-x="autonomous | ||
| custom element">autonomous custom elements</span>. Each <code>main</code> element must be a | ||
| <span>hierarchically correct <code>main</code> element</span>.</p> | ||
|
|
||
| <div class="example"> | ||
|
|
||
|
|
@@ -19247,6 +19252,35 @@ included with Exhibit B. | |
| </footer> | ||
| </html></pre> | ||
|
|
||
| <p>In the following example, multiple <code>main</code> elements are used and script is used to | ||
| make navigation work without a server roundtrip and to set the <code | ||
| data-x="attr-hidden">hidden</code> attribute on those that are not current: | ||
|
|
||
| <pre><!doctype html> | ||
| <html lang=en-CA> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good example! |
||
| <meta charset=utf-8> | ||
| <title> … </title> | ||
| <link rel=stylesheet href=spa.css> | ||
| <script src=spa.js async></script> | ||
| <nav> | ||
| <a href=/>Home</a> | ||
| <a href=/about>About</a> | ||
| <a href=/contact>Contact</a> | ||
| </nav> | ||
| <main> | ||
| <h1>Home</h1> | ||
| … | ||
| </main> | ||
| <main hidden> | ||
| <h1>About</h1> | ||
| … | ||
| </main> | ||
| <main hidden> | ||
| <h1>Contact</h1> | ||
| … | ||
| </main> | ||
| <footer>Made with ❤️ by <a href=https://example.com/>Example 👻</a>.</footer></pre> | ||
|
|
||
| </div> | ||
|
|
||
|
|
||
|
|
@@ -19262,7 +19296,7 @@ included with Exhibit B. | |
| <dd>As a child of a <code>dl</code> element.</dd> | ||
| <dt><span data-x="concept-element-content-model">Content model</span>:</dt> | ||
| <dd>If the element is a child of a <code>dl</code> element: one or more <code>dt</code> elements followed by one or more <code>dd</code> elements, optionally intermixed with <span>script-supporting elements</span>.</dd> | ||
| <dd>If the element is not a child of a <code>dl</code> element: <span>Flow content</span>.</dd> | ||
| <dd>If the element is not a child of a <code>dl</code> element: <span>flow content</span>.</dd> | ||
| <dt><span data-x="concept-element-attributes">Content attributes</span>:</dt> | ||
| <dd><span>Global attributes</span></dd> | ||
| <dt><span data-x="concept-element-dom">DOM interface</span>:</dt> | ||
|
|
@@ -116530,10 +116564,10 @@ interface <dfn>External</dfn> { | |
|
|
||
| <tr> | ||
| <th><code>main</code></th> | ||
| <td>Container for the dominant contents of another element</td> | ||
| <td>Container for the dominant contents of the document</td> | ||
| <td><span data-x="Flow content">flow</span>; | ||
| <span data-x="Palpable content">palpable</span></td> | ||
| <td><span data-x="Flow content">flow</span></td> | ||
| <td><span data-x="Flow content">flow</span>*</td> | ||
| <td><span data-x="Flow content">flow</span></td> | ||
| <td><span data-x="global attributes">globals</span></td> | ||
| <td><code>HTMLElement</code></td> | ||
|
|
@@ -117416,7 +117450,6 @@ interface <dfn>External</dfn> { | |
| <code>ins</code>; | ||
| <code>kbd</code>; | ||
| <code>label</code>; | ||
| <code>main</code>; | ||
| <code>map</code>; | ||
| <code>mark</code>; | ||
| <span>MathML <code>math</code></span>; | ||
|
|
@@ -117459,6 +117492,7 @@ interface <dfn>External</dfn> { | |
| <td> | ||
| <code>area</code> (if it is a descendant of a <code>map</code> element); | ||
| <code>link</code> (if it is <span>allowed in the body</span>); | ||
| <code>main</code> (if it is a <span>hierarchically correct <code>main</code> element</span>); | ||
| <code>meta</code> (if the <code data-x="attr-itemprop">itemprop</code> attribute is present) | ||
|
|
||
| <tr> | ||
|
|
@@ -120690,6 +120724,7 @@ INSERT INTERFACES HERE | |
| Alfred Agrell, <!-- Alcaro on GitHub --> | ||
| Ali Juma, | ||
| Alice Boxhall, | ||
| Alice Wonder, | ||
| Allan Clements, | ||
| Allen Wirfs-Brock, | ||
| Alex Komoroske, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be clear, this is a change that could have been made without the other changes in this PR, right? This was inaccurate before as well, since headers and footers could also be inside the body. If that's not the right way to think of it, I might be missing something that I should be paying attention to elsewhere in these changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I haven't actually looked at when this was written, but that seems correct.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems this description of the
bodyelement goes back to 2006, before themainelement was introduced.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for checking that.