-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Make underscore-prefixed attributes formally valid (works AS IS in all existing browsers) #2250
Comments
Working in browsers is not related to document conformance, you're right. This is indeed entirely about document conformance. But I don't think there's benefit in splitting the ecosystem into two prefixes ( |
@domenic One of the main points of HTML5 compared with XHTML was to be based on speccing existing implementations and removing artificial limitations that don’t correspond to reality. The invalidity of underscore-prefixed attributes is an artificial limitation. To be clear, that’s not about trying to change the approach already used in existing libraries like Angular, but about preventing newer web-based products from being forced to ignore validity over and over again. Fwiw, I did always care about validity, but I do currently use underscore-prefixed attributes when adding them dynamically via JS (so they are just not discoverable by validator). Making underscore-prefixed attributes formally valid would just allow to spread their use to static HTML by removing the artificial limitation not corresponding to reality. I believe most of web developers aware of the change would immediately and completely drop using the |
I think you're confusing the implementation-facing aspects of HTML with the document conformance requirements. From one perspective, every document conformance requirement is an artificial limitation. But these limitations are in place for good reason! In addition to the reason I mentioned above for this specific case (not splitting the ecosystem into two approaches for custom data attributes), see also https://html.spec.whatwg.org/#conformance-requirements-for-authors for a more general set of reasons why we impose these restrictions. They may be artificial, but they're not arbitrary, and they definitely correspond to reality! |
@domenic Redirecting to a large document is typically not too helpful. Quoting a relevant minimal part right here could be. Fwiw, note that not all custom attributes are data attributes. For example, I often use boolean custom attributes (with no values). These are different paragidms. |
I'm sorry, if you're not able to read the spec you're filing bugs on, especially the small section you're discussing changing, we're not going to have a very productive conversation :( |
@domenic Please be more specific if you really intend to be helpful and not just to practice eloquence. Even if I read the entire spec, it may still be unclear what exact part of it you mean; one does not exclude the other. If needed, feel free to contact me privately to prevent polluting the thread. Thanks.
Reality is that underscore-prefixed attributes work in all existing browsers, but the spec does not account for this. And while using absolutely arbitrary names of custom attributes would be unsafe due to potential conflicts with same-name attributes standardized in the future, the underscore prefix will certainly never be used for standard attributes, so it is absolutely safe. |
That is perfectly valid use of Is there a reason you don't use the
I understand that the API doesn't help for markup or in selectors, though.
It accounts for it in that it requires them to work in UAs.
Any prefix will work in browsers and most of them will never conflict with future additions to HTML... In the WICG thread it has already been suggested to allow other prefixes. Do you think people will be happy with the underscore, or still use some other prefix because underscore is ugly (or whatever)? I think this is a tradeoff between
and
|
@Marat-Tanalin, my browser had great trouble loading the full spec to view that small section, so here is a link to that section from the multipage document: (https://html.spec.whatwg.org/multipage/introduction.html#conformance-requirements-for-authors).
@zcorpan, that is a good point. Developers who wish to be compliant and also maintain readable source may be happy, as evidenced by some of the prominent individuals supporting the wicg thread. Developers find the extra word/characters distracting to the flow of their documentation. Google and their Angular library may be one example. A similar example may be the removal of
@domenic, could |
@jonathantneal they could be, but it would complicate the processing model and not over much new utility. What I think we want to do with attributes is enable hooks for them just as we did with custom elements. And basically allow any attribute with a hyphen (except for the couple that were already minted) to be used as custom global attribute, with the appropriate JavaScript binding. That would offer something to developers (just like |
@zcorpan Hello, Simon. Thanks for the substantive comment.
Right, I use custom attributes in selectors. And I would also like to use them in markup immediately once they are legitimized. Also, I find the
Right, but it is obviously not what I mean.
I believe such other prefixes are proposed not because they are actually good or usable, but just as a suboptimal partial solution of the “better than nothing” category. Actually, I would continue to use underscore as long as other formally valid options are longer than one character, so introducing such options wouldn’t help much. Fwiw, the big advantage of |
@jonathantneal Hello, Jonathan.
While such synonymization might sound good at first glance, this would probably lead to confusion and complexity in terms of e. g. priority when both |
Just to note that "support" here just means I hearted the post. I don't actually like this idea, though I do think it's better than |
Let's continue this discussion in #2271; the two proposals are for the same issue. |
It makes sense to make underscore-prefixed (
_
) custom HTML attributes formally valid:Facts and advantages
data-
).data-
(custom attributes are for data to the same extent as all standard attributes are) or with any other letter-based prefix likemy-
.The
data-
prefix is omitted/ignored in practiceThe currently allowed
data-
prefix is in fact too long (5-times longer than_
) and therefore just omitted/ignored in practice (e. g. the Angular JS library usesng-*
attributes), so HTML markup inevitably gets invalid anyway (and not future-proof compared with the underscore prefix).No interrelation with
data-
anddataset
Underscore-prefixed attributes should not affect
data-
prefixed attributes and/or thedataset
DOM property in any way, and vice versa._
anddata-
prefixed attributes should just coexist.Hyphen prefix as an option
Alternatively, hyphen (
-
) prefix could be used instead of underscore (_
), but actually, both work in all browsers, both are future-proof, so both should be formally valid. Underscore would just be enough.Also, from the two, the underscore prefix is reportedly the only XML-compatible option that is also confirmed by Simon Pieters (@zcorpan).
The text was updated successfully, but these errors were encountered: