Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can data attributes begin with a number? (e.g. data-1234="")

I know that the value of identifiers can't begin with numbers or hyphens, but can data attributes? And if so is there any reason for not using data--="" (not that I would, just curiosity speaking)

like image 323
Charlotte Dann Avatar asked Sep 15 '25 02:09

Charlotte Dann


1 Answers

See the definition

A custom data attribute is an attribute in no namespace whose name starts with the string "data-", has at least one character after the hyphen, is XML-compatible, and contains no characters in the range U+0041 to U+005A (LATIN CAPITAL LETTER A to LATIN CAPITAL LETTER Z).

The reason is XML compability. And of course javascript compability because var 1234 is not possible.

like image 91
Oliver Avatar answered Sep 17 '25 18:09

Oliver