Answer the question
In order to leave comments, you need to log in
Tag Attributes in HTML5
Hello!
I'm trying to understand the possibility of setting free attributes for tags in HTML5.
I have not yet found a direct ban anywhere, but there is no explicit permission either.
The data-* attribute is familiar, but the correctness of such, for example, an entry is of interest: <tag anyAttr="value">/<tag>
Through JS, it is quite possible to reach the tag: http://jsfiddle.net/j8GjS/
Are there any "legal" documents? Do all browsers work with the example code? What is the rule for standards:
- everything that is not forbidden
is allowed - everything that is not allowed is forbidden
Thank you in advance.
PS so far I have only found: http://www.w3.org/TR/html-markup/syntax.html - there is no direct ban
Answer the question
In order to leave comments, you need to log in
in my practice of layout and js development, I have not yet encountered the problem of using non-standard attributes and I think that "everything that is not prohibited is allowed" (imho)
To some extent, everything that is not forbidden is allowed, but you need to understand the consequences.
For example, what happens if you do not write custom attributes without the data- prefix?
A little easier: even before html5, you could use any attributes, just some had their own interpretation rules, such as href in a, was interpreted as an onclick link to a certain path (event), you can use any attributes, but it's worth considering what may arise " conflict" specification. Why use data? - "out of the box" storage of objects and values of different types (json format) during interpretation, in the rest you will have to do decode + "buns" to distinguish between "1", 1, true, TRUE and so on.
The W3C spec doesn't list options other than data-*. It can be assumed that support for custom attributes without the "data-" prefix is unofficial support from browsers. If it works, then you can use it, but if it's not in the standards, then don't be surprised if your page stops working as you expected.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question