I was wondering if you can have a data-* attribute that is just data-
? or just data
?
What are the rules here?
The data-* attribute is a Global Attribute, and can be used on any HTML element.
HTML5 is designed with extensibility in mind for data that should be associated with a particular element but need not have any defined meaning. data-* attributes allow us to store extra information on standard, semantic HTML elements without other hacks such as non-standard attributes, or extra properties on DOM.
The data attribute name must be at least one character long and must be prefixed with ' data- '. It should not contain any uppercase letters. Attribute Value. The attribute value can be any string.
A data attribute is a custom attribute that stores information. Data attributes always start with “data-” then followed with a descriptive name of the data that is being stored. You can have multiple data attributes on an element and be used on any HTML element.
The data-*
attribute rules are specified in the HTML5 specification.
From the spec:
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).
Note that it also restricts the usage to lower case, however another note applies:
All attributes on HTML elements in HTML documents get ASCII-lowercased automatically, so the restriction on ASCII uppercase letters doesn't affect such documents
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With