I am developing a JS plugin for serving of retina images. The attributes that identify these images are supposed to be the following:
data-retina@2x
,
[email protected]
,
[email protected]
.
Could you tell me if these attributes are valid? What characters are allowed (not allowed) in the names of custom data-* attributes in HTML and XHTML?
See the definition of the data-*
attribute in the W3C HTML5 Recommendation:
In HTML5, the name must be XML-compatible (and it gets ASCII-lowercased automatically).
In XHTML5, the name must be XML-compatible and must not contain uppercase ASCII letters.
The definition of XML-compatible says that it
:
charactersName
production in the XML 1.0 specificationThis Name
production lists which characters are allowed.
tl;dr: For the part after data-
, you may use the following characters:
0
-9
a
-z
A
-Z
(not in XHTML5)-
_
.
·
and characters from these Unicode ranges:
‿
⁀
)So the @
(U+0040) is not allowed.