Skip to content

Commit 1dec930

Browse files
authored
Restrict the main element to be used once per document
Multiple main elements are still allowed if all or all but one have the hidden attribute specified. The main element is also restricted in terms of where it can appear in a document. It can only have html, body, form without accessible name, div, and autonomous custom elements as ancestors. This also slightly alters the definition of the body element as it effectively encompasses all content of a document, except for some metadata. Fixes #100.
1 parent ad4ddd8 commit 1dec930

File tree

2 files changed

+57
-22
lines changed

2 files changed

+57
-22
lines changed

images/content-venn.svg

Lines changed: 1 addition & 1 deletion
Loading

source

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10696,7 +10696,7 @@ console.assert(image.height === 200);</pre>
1069610696
<li><code>kbd</code></li>
1069710697
<li><code>label</code></li>
1069810698
<li><code>link</code> (if it is <span>allowed in the body</span>)</li>
10699-
<li><code>main</code></li>
10699+
<li><code>main</code> (if it is a <span>hierarchically correct <code>main</code> element</span>)</li>
1070010700
<li><code>map</code></li>
1070110701
<li><code>mark</code></li>
1070210702
<li><span>MathML <code>math</code></span></li>
@@ -15170,7 +15170,7 @@ interface <dfn>HTMLBodyElement</dfn> : <span>HTMLElement</span> {};
1517015170
<dd w-nohtml>Uses <code>HTMLBodyElement</code>.</dd>
1517115171
</dl>
1517215172

15173-
<p>The <code>body</code> element <span>represents</span> the main content of the document.</p>
15173+
<p>The <code>body</code> element <span>represents</span> the contents of the document.</p>
1517415174

1517515175
<p>In conforming documents, there is only one <code>body</code> element. The <code
1517615176
data-x="dom-document-body">document.body</code> IDL attribute provides scripts with easy access to
@@ -15550,7 +15550,7 @@ interface <dfn>HTMLBodyElement</dfn> : <span>HTMLElement</span> {};
1555015550
<dt><span data-x="concept-element-contexts">Contexts in which this element can be used</span>:</dt>
1555115551
<dd>Where <span>flow content</span> is expected.</dd>
1555215552
<dt><span data-x="concept-element-content-model">Content model</span>:</dt>
15553-
<dd><span>Flow content</span>, but with no <code>main</code> element descendants.</dd>
15553+
<dd><span>Flow content</span>.</dd>
1555415554
<dt><span data-x="concept-element-attributes">Content attributes</span>:</dt>
1555515555
<dd><span>Global attributes</span></dd>
1555615556
<dt><span data-x="concept-element-dom">DOM interface</span>:</dt>
@@ -15727,7 +15727,7 @@ interface <dfn>HTMLBodyElement</dfn> : <span>HTMLElement</span> {};
1572715727
<dt><span data-x="concept-element-contexts">Contexts in which this element can be used</span>:</dt>
1572815728
<dd>Where <span>flow content</span> is expected.</dd>
1572915729
<dt><span data-x="concept-element-content-model">Content model</span>:</dt>
15730-
<dd><span>Flow content</span>, but with no <code>main</code> element descendants.</dd>
15730+
<dd><span>Flow content</span>.</dd>
1573115731
<dt><span data-x="concept-element-attributes">Content attributes</span>:</dt>
1573215732
<dd><span>Global attributes</span></dd>
1573315733
<dt><span data-x="concept-element-dom">DOM interface</span>:</dt>
@@ -16116,7 +16116,8 @@ Space is not the only void</pre>
1611616116
<dt><span data-x="concept-element-contexts">Contexts in which this element can be used</span>:</dt>
1611716117
<dd>Where <span>flow content</span> is expected.</dd>
1611816118
<dt><span data-x="concept-element-content-model">Content model</span>:</dt>
16119-
<dd><span>Flow content</span>, but with no <code>header</code>, <code>footer</code>, or <code>main</code> element descendants.</dd>
16119+
<dd><span>Flow content</span>, but with no <code>header</code> or <code>footer</code> element
16120+
descendants.</dd>
1612016121
<dt><span data-x="concept-element-attributes">Content attributes</span>:</dt>
1612116122
<dd><span>Global attributes</span></dd>
1612216123
<dt><span data-x="concept-element-dom">DOM interface</span>:</dt>
@@ -16202,7 +16203,8 @@ Space is not the only void</pre>
1620216203
<dt><span data-x="concept-element-contexts">Contexts in which this element can be used</span>:</dt>
1620316204
<dd>Where <span>flow content</span> is expected.</dd>
1620416205
<dt><span data-x="concept-element-content-model">Content model</span>:</dt>
16205-
<dd><span>Flow content</span>, but with no <code>header</code>, <code>footer</code>, or <code>main</code> element descendants.</dd>
16206+
<dd><span>Flow content</span>, but with no <code>header</code> or <code>footer</code> element
16207+
descendants.</dd>
1620616208
<dt><span data-x="concept-element-attributes">Content attributes</span>:</dt>
1620716209
<dd><span>Global attributes</span></dd>
1620816210
<dt><span data-x="concept-element-dom">DOM interface</span>:</dt>
@@ -18960,9 +18962,9 @@ first matching case):&lt;/p&gt;
1896018962
<dt><span data-x="concept-element-contexts">Contexts in which this element can be used</span>:</dt>
1896118963
<dd>Where <span>flow content</span> is expected.</dd>
1896218964
<dt><span data-x="concept-element-content-model">Content model</span>:</dt>
18963-
<dd>Either: One <code>figcaption</code> element followed by <span>flow content</span>.</dd>
18964-
<dd>Or: <span>Flow content</span> followed by one <code>figcaption</code> element.</dd>
18965-
<dd>Or: <span>Flow content</span>.</dd>
18965+
<dd>Either: one <code>figcaption</code> element followed by <span>flow content</span>.</dd>
18966+
<dd>Or: <span>flow content</span> followed by one <code>figcaption</code> element.</dd>
18967+
<dd>Or: <span>flow content</span>.</dd>
1896618968
<dt><span data-x="concept-element-attributes">Content attributes</span>:</dt>
1896718969
<dd><span>Global attributes</span></dd>
1896818970
<dt><span data-x="concept-element-dom">DOM interface</span>:</dt>
@@ -19182,7 +19184,8 @@ included with Exhibit B.
1918219184
<dd><span>Flow content</span>.</dd>
1918319185
<dd><span>Palpable content</span>.</dd>
1918419186
<dt><span data-x="concept-element-contexts">Contexts in which this element can be used</span>:</dt>
19185-
<dd>Where <span>flow content</span> is expected.</dd>
19187+
<dd>Where <span>flow content</span> is expected, but only if it is a <span>hierarchically correct
19188+
<code>main</code> element</span>.</dd>
1918619189
<dt><span data-x="concept-element-content-model">Content model</span>:</dt>
1918719190
<dd><span>Flow content</span>.</dd>
1918819191
<dt><span data-x="concept-element-attributes">Content attributes</span>:</dt>
@@ -19191,15 +19194,17 @@ included with Exhibit B.
1919119194
<dd>Uses <code>HTMLElement</code>.</dd>
1919219195
</dl>
1919319196

19194-
<p>The <code>main</code> element can be used as a container for the dominant contents of the
19195-
document. It <span>represents</span> its children.</p>
19197+
<p>The <code>main</code> element <span>represents</span> the dominant contents of the
19198+
document.</p>
1919619199

19197-
<p class="note">The <code>main</code> element is distinct from the <code>section</code> and
19198-
<code>article</code> elements in that the <code>main</code> element does not contribute to the
19199-
document <span>outline</span>.</p>
19200+
<p>A document must not have more than one <code>main</code> element that does not have the <code
19201+
data-x="attr-hidden">hidden</code> attribute specified.</p>
1920019202

19201-
<p class="note">While there is no restriction as to the number of <code>main</code> elements in a
19202-
document, web developers are encouraged to stick to a single element.</p>
19203+
<p>A <dfn>hierarchically correct <code>main</code> element</dfn> is one whose ancestor elements
19204+
are limited to <code>html</code>, <code>body</code>, <code>div</code>, <code>form</code> without
19205+
an <span data-x="concept-accessible-name">accessible name</span>, and <span data-x="autonomous
19206+
custom element">autonomous custom elements</span>. Each <code>main</code> element must be a
19207+
<span>hierarchically correct <code>main</code> element</span>.</p>
1920319208

1920419209
<div class="example">
1920519210

@@ -19241,6 +19246,35 @@ included with Exhibit B.
1924119246
&lt;/footer>
1924219247
&lt;/html></pre>
1924319248

19249+
<p>In the following example, multiple <code>main</code> elements are used and script is used to
19250+
make navigation work without a server roundtrip and to set the <code
19251+
data-x="attr-hidden">hidden</code> attribute on those that are not current:
19252+
19253+
<pre>&lt;!doctype html>
19254+
&lt;html lang=en-CA>
19255+
&lt;meta charset=utf-8>
19256+
&lt;title> &hellip; &lt;/title>
19257+
&lt;link rel=stylesheet href=spa.css>
19258+
&lt;script src=spa.js async>&lt;/script>
19259+
&lt;nav>
19260+
&lt;a href=/>Home&lt;/a>
19261+
&lt;a href=/about>About&lt;/a>
19262+
&lt;a href=/contact>Contact&lt;/a>
19263+
&lt;/nav>
19264+
&lt;main>
19265+
&lt;h1>Home&lt;/h1>
19266+
&hellip;
19267+
&lt;/main>
19268+
&lt;main hidden>
19269+
&lt;h1>About&lt;/h1>
19270+
&hellip;
19271+
&lt;/main>
19272+
&lt;main hidden>
19273+
&lt;h1>Contact&lt;/h1>
19274+
&hellip;
19275+
&lt;/main>
19276+
&lt;footer>Made with ❤️ by &lt;a href=https://example.com/>Example 👻&lt;/a>.&lt;/footer></pre>
19277+
1924419278
</div>
1924519279

1924619280

@@ -19256,7 +19290,7 @@ included with Exhibit B.
1925619290
<dd>As a child of a <code>dl</code> element.</dd>
1925719291
<dt><span data-x="concept-element-content-model">Content model</span>:</dt>
1925819292
<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>
19259-
<dd>If the element is not a child of a <code>dl</code> element: <span>Flow content</span>.</dd>
19293+
<dd>If the element is not a child of a <code>dl</code> element: <span>flow content</span>.</dd>
1926019294
<dt><span data-x="concept-element-attributes">Content attributes</span>:</dt>
1926119295
<dd><span>Global attributes</span></dd>
1926219296
<dt><span data-x="concept-element-dom">DOM interface</span>:</dt>
@@ -116450,10 +116484,10 @@ interface <dfn>External</dfn> {
116450116484

116451116485
<tr>
116452116486
<th><code>main</code></th>
116453-
<td>Container for the dominant contents of another element</td>
116487+
<td>Container for the dominant contents of the document</td>
116454116488
<td><span data-x="Flow content">flow</span>;
116455116489
<span data-x="Palpable content">palpable</span></td>
116456-
<td><span data-x="Flow content">flow</span></td>
116490+
<td><span data-x="Flow content">flow</span>*</td>
116457116491
<td><span data-x="Flow content">flow</span></td>
116458116492
<td><span data-x="global attributes">globals</span></td>
116459116493
<td><code>HTMLElement</code></td>
@@ -117336,7 +117370,6 @@ interface <dfn>External</dfn> {
117336117370
<code>ins</code>;
117337117371
<code>kbd</code>;
117338117372
<code>label</code>;
117339-
<code>main</code>;
117340117373
<code>map</code>;
117341117374
<code>mark</code>;
117342117375
<span>MathML <code>math</code></span>;
@@ -117379,6 +117412,7 @@ interface <dfn>External</dfn> {
117379117412
<td>
117380117413
<code>area</code> (if it is a descendant of a <code>map</code> element);
117381117414
<code>link</code> (if it is <span>allowed in the body</span>);
117415+
<code>main</code> (if it is a <span>hierarchically correct <code>main</code> element</span>);
117382117416
<code>meta</code> (if the <code data-x="attr-itemprop">itemprop</code> attribute is present)
117383117417

117384117418
<tr>
@@ -120610,6 +120644,7 @@ INSERT INTERFACES HERE
120610120644
Alfred Agrell, <!-- Alcaro on GitHub -->
120611120645
Ali Juma,
120612120646
Alice Boxhall,
120647+
Alice Wonder,
120613120648
Allan Clements,
120614120649
Allen Wirfs-Brock,
120615120650
Alex Komoroske,

0 commit comments

Comments
 (0)