html5 – Can data- * attributes be attribute names consisting only of numbers?

Question: Question:

In HTML5 data- * attribute

  1. data- followed by at least one character
  2. Must be XML-compatible
  3. Do not contain ASCII capital letters

Is requesting three*-attributes

The data-1 attribute of <div data-1="1"></div> satisfies all the above three, so I think it is HTML valid, but is it correct?

Answer: Answer:

There is no mistake.

It's readable by the standard, and the dataset's setter algorithm doesn't error names that start with a number. The code below works on Chrome, Edge, Firefox and Safari.

document.body.dataset['012'] = 'value';

However, if you start with a number, dot format access will not be possible.

document.body.dataset.012 = 'value'; // SyntaxError
Scroll to Top