Skip to content

Commit

Permalink
Disambiguate attribute declarations from content attributes
Browse files Browse the repository at this point in the history
The change updates the spec to use the term “attribute declaration” in
all cases where what the spec is referring to is actually the syntax for
declaring attributes in markup.

Otherwise, without this change, the spec uses the same term “attribute”
to refer both to attribute declarations in markup and to actual content
attributes as they exist in the DOM.

And we have evidence of authors being confused due to that ambiguous use
of the same term to refer to different things — and evidence suggesting
the ambiguous usage promotes the wrong mental model of HTML for authors.
  • Loading branch information
sideshowbarker committed Nov 9, 2024
1 parent 0511ae0 commit 776ab2b
Showing 1 changed file with 50 additions and 46 deletions.
96 changes: 50 additions & 46 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -677,11 +677,11 @@ interface <dfn data-x="">Example</dfn> {

<pre><code class="html">&lt;a href="demo.html">simple&lt;/a></code></pre>

<p><span data-x="syntax-attributes">Attributes</span> are placed inside the start tag, and consist
of a <span data-x="syntax-attribute-name">name</span> and a <span
data-x="syntax-attribute-value">value</span>, separated by an "<code data-x="">=</code>" character.
The attribute value can remain <a href="#unquoted">unquoted</a> if it doesn't contain <span>ASCII
whitespace</span> or any of <code data-x="">"</code> <code data-x="">'</code> <code
<p><span data-x="syntax-attribute-declarations">Attribute declarations</span> are placed inside
the start tag, and consist of a <span data-x="syntax-attribute-name">name</span> and a <span
data-x="syntax-attribute-value">value</span>, separated by an "<code data-x="">=</code>"
character. The attribute value can remain <a href="#unquoted">unquoted</a> if it doesn't contain
<span>ASCII whitespace</span> or any of <code data-x="">"</code> <code data-x="">'</code> <code
data-x="">`</code> <code data-x="">=</code> <code data-x="">&lt;</code> or <code
data-x="">&gt;</code>. Otherwise, it has to be quoted using either single or double quotes. The
value, along with the "<code data-x="">=</code>" character, can be omitted altogether if the value
Expand Down Expand Up @@ -1174,8 +1174,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<div class="example">

<p>For example, this is why the U+0060 GRAVE ACCENT character (`) is not allowed in unquoted
attributes. In certain legacy user agents, <!-- namely IE --> it is sometimes treated as a
quote character.</p>
attribute declarations. In certain legacy user agents, <!-- namely IE --> it is sometimes
treated as a quote character.</p>

</div>

Expand Down Expand Up @@ -1246,18 +1246,18 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute

<div class="example">

<p>For example, "attributes" in end tags are ignored currently, but they are invalid, in case a
future change to the language makes use of that syntax feature without conflicting with
already-deployed (and valid!) content.</p>
<p>For example, attribute declarations in end tags are ignored currently, but they are invalid,
in case a future change to the language makes use of that syntax feature without conflicting
with already-deployed (and valid!) content.</p>

</div>
</dd>
</dl>

<p>Some authors find it helpful to be in the practice of always quoting all attributes and always
including all optional tags, preferring the consistency derived from such custom over the minor
benefits of terseness afforded by making use of the flexibility of the HTML syntax. To aid such
authors, conformance checkers can provide modes of operation wherein such conventions are
<p>Some authors find it helpful to be in the practice of always quoting all attribute values and
always including all optional tags, preferring the consistency derived from such custom over the
minor benefits of terseness afforded by making use of the flexibility of the HTML syntax. To aid
such authors, conformance checkers can provide modes of operation wherein such conventions are
enforced.</p>


Expand Down Expand Up @@ -45441,7 +45441,8 @@ interface <dfn interface>HTMLTableCellElement</dfn> : <span>HTMLElement</span> {

<p class="note">There is no particular significance to the way some of the attributes have their
values quoted and others don't. The HTML syntax allows a variety of equally valid ways to specify
attributes, as discussed <span data-x="syntax-attributes">in the syntax section</span>.</p>
attributes, as discussed <span data-x="syntax-attribute-declarations">in the syntax
section</span>.</p>

<p>For example, if the customer entered "Denise Lawrence" as their name, "555-321-8642" as their
telephone number, did not specify an email address, asked for a medium-sized pizza, selected the
Expand Down Expand Up @@ -122895,17 +122896,17 @@ dictionary <dfn dictionary>StorageEventInit</dfn> : <span>EventInit</span> {
<li>The next few characters of a start tag must be the element's <span
data-x="syntax-tag-name">tag name</span>.</li>

<li>If there are to be any attributes in the next step, there must first be one or more
<span>ASCII whitespace</span>.</li>
<li>If there are to be any attribute declarations in the next step, there must first be one or
more <span>ASCII whitespace</span>.</li>

<li>Then, the start tag may have a number of attributes, the <span
data-x="syntax-attributes">syntax for which</span> is described below. Attributes must be
separated from each other by one or more <span>ASCII whitespace</span>.</li>
<li>Then, the start tag may have a number of attribute declarations, the <span
data-x="syntax-attribute-declarations">syntax for which</span> is described below. Attribute
declarations must be separated from each other by one or more <span>ASCII whitespace</span>.</li>

<li>After the attributes, or after the <span data-x="syntax-tag-name">tag name</span> if there
are no attributes, there may be one or more <span>ASCII whitespace</span>. (Some attributes are
required to be followed by a space. See the <span data-x="syntax-attributes">attributes
section</span> below.)</li>
<li>After the attribute declarations, or after the <span data-x="syntax-tag-name">tag name</span>
if there are no attributes, there may be one or more <span>ASCII whitespace</span>. (Some
attribute declarations are required to be followed by a space. See the <span
data-x="syntax-attribute-declarations">attribute declarations</span> section below.)</li>

<li>Then, if the element is one of the <span>void elements</span>, or if the element is a <span
data-x="foreign elements">foreign element</span>, then there may be a single U+002F SOLIDUS
Expand Down Expand Up @@ -122938,10 +122939,10 @@ dictionary <dfn dictionary>StorageEventInit</dfn> : <span>EventInit</span> {
</ol>


<h5>Attributes</h5>
<h5>Attribute declarations</h5>

<p><dfn data-x="syntax-attributes">Attributes</dfn> for an element are expressed inside the
element's start tag.</p>
<p><dfn data-x="syntax-attribute-declarations">Attribute declarations</dfn> for an element are
expressed inside the element's start tag.</p>

<p>Attributes have a name and a value. <dfn data-x="syntax-attribute-name">Attribute names</dfn>
must consist of one or more characters other than <span data-x="control">controls</span>,
Expand All @@ -122955,7 +122956,7 @@ dictionary <dfn dictionary>StorageEventInit</dfn> : <span>EventInit</span> {
except with the additional restriction that the text cannot contain an <span
data-x="syntax-ambiguous-ampersand">ambiguous ampersand</span>.</p>

<p>Attributes can be specified in four different ways:</p>
<p>Attributes can be declared in four different ways:</p>

<dl>
<dt>Empty attribute syntax</dt>
Expand All @@ -122973,8 +122974,8 @@ dictionary <dfn dictionary>StorageEventInit</dfn> : <span>EventInit</span> {

</div>

<p>If an attribute using the empty attribute syntax is to be followed by another attribute, then
there must be <span>ASCII whitespace</span> separating the two.</p>
<p>If an attribute declaration using the empty attribute syntax is to be followed by another
attribute declaration, then there must be <span>ASCII whitespace</span> separating the two.</p>
</dd>

<dt id="unquoted">Unquoted attribute value syntax</dt>
Expand Down Expand Up @@ -123026,9 +123027,9 @@ dictionary <dfn dictionary>StorageEventInit</dfn> : <span>EventInit</span> {

</div>

<p>If an attribute using the unquoted attribute syntax is to be followed by another attribute or
by the optional U+002F SOLIDUS character (/) allowed in step 6 of the <span
data-x="syntax-start-tag">start tag</span> syntax above, then there must be <span>ASCII
<p>If an attribute declaration using the unquoted attribute syntax is to be followed by another
attribute declaration or by the optional U+002F SOLIDUS character (/) allowed in step 6 of the
<span data-x="syntax-start-tag">start tag</span> syntax above, then there must be <span>ASCII
whitespace</span> separating the two.</p>
</dd>

Expand All @@ -123052,8 +123053,9 @@ dictionary <dfn dictionary>StorageEventInit</dfn> : <span>EventInit</span> {

</div>

<p>If an attribute using the single-quoted attribute syntax is to be followed by another
attribute, then there must be <span>ASCII whitespace</span> separating the two.</p>
<p>If an attribute declaration using the single-quoted attribute syntax is to be followed by
another attribute declaration, then there must be <span>ASCII whitespace</span> separating the
two.</p>
</dd>

<dt>Double-quoted attribute value syntax</dt>
Expand All @@ -123076,13 +123078,14 @@ dictionary <dfn dictionary>StorageEventInit</dfn> : <span>EventInit</span> {

</div>

<p>If an attribute using the double-quoted attribute syntax is to be followed by another
attribute, then there must be <span>ASCII whitespace</span> separating the two.</p>
<p>If an attribute declaration using the double-quoted attribute syntax is to be followed by
another attribute declaration, then there must be <span>ASCII whitespace</span> separating the
two.</p>
</dd>
</dl>

<p>There must never be two or more attributes on the same start tag whose names are an <span>ASCII
case-insensitive</span> match for each other.</p>
<p>There must never be two or more attribute declarations in the same start tag whose names are an
<span>ASCII case-insensitive</span> match for each other.</p>

<hr>

Expand Down Expand Up @@ -123858,14 +123861,15 @@ dictionary <dfn dictionary>StorageEventInit</dfn> : <span>EventInit</span> {
<tr>
<td><dfn data-x="parse-error-duplicate-attribute">duplicate-attribute</dfn>
<td><p>This error occurs if the parser encounters an <span
data-x="syntax-attributes">attribute</span> in a tag that already has an attribute with the
same name. The parser ignores all such duplicate occurrences of the attribute.
data-x="syntax-attribute-declarations">attribute declaration</span> in a tag that already has
an attribute with the same name. The parser ignores all such duplicate occurrences of the
attribute.

<tr>
<td><dfn data-x="parse-error-end-tag-with-attributes">end-tag-with-attributes</dfn>
<td><p>This error occurs if the parser encounters an <span data-x="syntax-end-tag">end
tag</span> with <span data-x="syntax-attributes">attributes</span>. Attributes in end tags are
ignored and do not make their way into the DOM.</p>
tag</span> with <span data-x="syntax-attribute-declarations">attribute declarations</span>.
Attribute declarations in end tags are ignored and do not result in attributes in the DOM.</p>

<tr>
<td><dfn data-x="parse-error-end-tag-with-trailing-solidus">end-tag-with-trailing-solidus</dfn>
Expand Down Expand Up @@ -123977,7 +123981,7 @@ dictionary <dfn dictionary>StorageEventInit</dfn> : <span>EventInit</span> {
<tr>
<td><dfn data-x="parse-error-missing-attribute-value">missing-attribute-value</dfn>
<td><p>This error occurs if the parser encounters a U+003E (>) <span>code point</span> where an
<span data-x="syntax-attributes">attribute</span> value is expected (e.g., <code
<span data-x="syntax-attribute-value">attribute value</span> is expected (e.g., <code
data-x="">&lt;div id=></code>). The parser treats the attribute as having an empty value.</p>

<tr>
Expand Down Expand Up @@ -124064,7 +124068,7 @@ dictionary <dfn dictionary>StorageEventInit</dfn> : <span>EventInit</span> {
<tr>
<td><dfn data-x="parse-error-missing-whitespace-between-attributes">missing-whitespace-between-attributes</dfn>
<td><p>This error occurs if the parser encounters <span
data-x="syntax-attributes">attributes</span> that are not separated by <span>ASCII
data-x="syntax-attribute-declarations">attributes</span> that are not separated by <span>ASCII
whitespace</span> (e.g., <code data-x="">&lt;div id="foo"class="bar"></code>). In this case the
parser behaves as if ASCII whitespace is present.</p>

Expand Down Expand Up @@ -124251,7 +124255,7 @@ dictionary <dfn dictionary>StorageEventInit</dfn> : <span>EventInit</span> {
<tr>
<td><dfn data-x="parse-error-unexpected-solidus-in-tag">unexpected-solidus-in-tag</dfn>
<td><p>This error occurs if the parser encounters a U+002F (/) <span>code point</span> that is
not a part of a quoted <span data-x="syntax-attributes">attribute</span> value and not
not a part of a quoted <span data-x="syntax-attribute-value">attribute value</span> and not
immediately followed by a U+003E (>) code point in a tag (e.g., <code data-x="">&lt;div /
id="foo"></code>). In this case the parser behaves as if it encountered <span>ASCII
whitespace</span>.</p>
Expand Down

0 comments on commit 776ab2b

Please sign in to comment.