In short, _
as the entire attribute's name, is considered wrong because since it is the only character it is also the first character, and as long as you are calling this an "HTML" attribute, there is indeed an HTML rule against attribute names starting with _
.
Explanation
From 20 SGML Declaration of HTML 4:
NAMING LCNMSTRT ""
UCNMSTRT ""
LCNMCHAR ".-_:"
UCNMCHAR ".-_:"
NAMECASE GENERAL YES
ENTITY NO
SGML and HTML Explained:
By default SGML presumes that names can only start with alphabetic characters, in either shift, with subsequent characters being alphanumeric. The LCNMSTRT and UCNMSTRT entries in the syntax clause allow other, non-alphanumeric, characters to be defined as name start characters, the LCNMCHAR and UCNMCHAR entries defining which non-alphanumeric characters can be used as name characters after a name start character.
So it we see _
is listed in LCNMCHAR
, UCNMCHAR
, and that they are to be after a name start
, not before.
Further Reading
Which ASCII characters are forbidden for use in SGML attributes?
data-*
attributes. I believe, you can usedata-_="choices"
._
is not a syntax error, butdiv
elements have no_
attribute, so it's not allowed. It would be the same forhello
. If you want custom attributes, usedata-*
.