Example:
<div my-attribute></div>
Is this valid HTML?
the HTML spec defines what a valid custom element name is but I can’t find anything about attributes. Are custom attributes valid as well if they contain a hyphen?
Example:
<div my-attribute></div>
Is this valid HTML?
the HTML spec defines what a valid custom element name is but I can’t find anything about attributes. Are custom attributes valid as well if they contain a hyphen?
Not sure if it’s the same thing so I’d wait for someone else to hop in, but given there are hyphened aria
and data
attributes I’d assume that’s valid.
Whether something is formally valid can be easily checked with a validator.
Custom attributes appear to only be valid on actual custom elements. This makes sense. But I’ll still have to find the text in the spec that defines this rule.
<div my-attribute>
<custom-element my-attribute>
or at least, on things that look like they might be custom elements
This thread will answer your question:
I would love custom-attributes containing hyphen!
Thanks. So this is still an open issue and no decision has been made yet to make custom attributes valid according to the HTML specification.