Are custom attributes containing a hyphen valid?


#1

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?


#2

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.


#3

Whether something is formally valid can be easily checked with a validator.


#4

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.


#5

or at least, on things that look like they might be custom elements :slight_smile:


#6

This thread will answer your question:

I would love custom-attributes containing hyphen!


#7

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.