Are custom attributes containing a hyphen valid?

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.

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

This thread will answer your question:

I would love custom-attributes containing hyphen!

2 Likes

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.