Open js-choi opened 6 years ago
This is covered in the HTML Standard already: https://html.spec.whatwg.org/multipage/introduction.html#a-quick-introduction-to-html
Attributes are placed inside the start tag, and consist of a name and a value, separated by an "=" character. The attribute value can remain unquoted if it doesn't contain ASCII whitespace or any of " ' ` = < or >. Otherwise, it has to be quoted using either single or double quotes. The value, along with the "=" character, can be omitted altogether if the value is the empty string.
@domenic: Indeed, and alt
does not act different than any other attribute in this manner. This issue’s about adding a specific informative note to the alt
attribute’s section, containing a cross reference to that introductory section and perhaps the normative clause governing empty attributes in general.
I don’t actually feel strongly one way or another, but @jasonkiss or @AmeliaBR might, since they were the ones who, respectively, were confused about the behavior and who raised this idea. @annevk suggested filing it to HTML.
I guess I'm just unsure why we would add this to alt's section, and not to e.g. checked, autocapitalize, or the many other attributes for which it's often the case that the empty string is a useful value.
I agree that the spec itself is clear in the section @domenic linked to. But the HTML spec is long, and authors aren't reading every section at the same time.
I think the confusion stems from the fact that most attributes where you'd use the empty attribute are boolean attributes, like checked
. The individual attributes are described by linking back to that section on boolean attributes, rather than by describing a special value for empty strings.
So when we do get to an attribute that isn't boolean, but has a special value for an empty string, it is maybe worth a very brief note (linking back to that introductory section on markup structure) about how no value in the markup is equivalent to the empty string value.
I'm not sure how many other non-boolean attributes have special behavior for empty strings, the ones that I could think of / find in a search of the W3C's repo (since this repo's source isn't searchable) are:
alt
crossorigin
contenteditable
(which is quasi-boolean: it uses the values "true"
and "false"
, with an empty string mapping to true, versus "inherit" for no attribute)lang
(empty string means unknown language, versus "inherit" for no attribute)autocomplete
(if I'm reading it correctly, an empty string is treated the same as no attribute specified)aria-current
, aria-haspopup
, & aria-invalid
This is not a humongous list. It seems feasible to linkify the phrase "empty string" to connect to a note about markup interpretation.
I think that'd be a bit of a layering violation (where it talks about the empty string it's very much a post-parse comparison), but I'd support giving all of these relevant examples.
I think the list is a decent bit longer than that; in particular anything with an invalid value default.
I'd prefer to be able to leave basic HTML syntax questions in a dedicated section, and not re-explain them in every attribute where they're relevant. Where does it end? Explaining that you don't need to use quotes around attributes for all attributes whose values don't usually contain spaces or other special characters? Explaining for every element that attributes are case-insensitive (when set by the parser)?
For what it's worth, I posted a Twitter poll to get a sense of developer knowledge about this aspect of parser behavior:
https://twitter.com/AmeliasBrain/status/967454652068327424
I've left the poll open until late Monday, but initial numbers suggest there are quite a few people who assume there is or could be a difference. Retweets to get a larger / more diverse sample would be appreciated (just try not to bias responses by linking to this issue until the poll is closed).
The alt attribute might be unique among the optional attributes in that it has historically been the focus of especial attention from accessibility guidelines and legal regulations. That’s presumably why the section devoted to its semantics goes over them in extra detail. That attention from the outside plus the persistent confusion on how precisely to use it might warrant special editorial treatment, among the optional attributes.
For what it's worth, the W3C editors decided to add a few minor edits to the section on alt
showing examples of alt specified without a value in the markup.
See w3c/html-aam#55. There was some browser-developer confusion on whether
<img alt>
is same as<img alt=''>
are equivalent versus distinguishable. The answer is that they are equivalent.It may be worth clarifying this in the HTML Standard itself to prevent future similar confusion.