L
L
Leonid2013-11-28 18:21:09
HTML
Leonid, 2013-11-28 18:21:09

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

4 answer(s)
S
Sergey Melnikov, 2013-11-28
@mlnkv

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)

I
Ilya Shabanov, 2013-11-28
@ishaba

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?

  • The document will be considered invalid.
  • In the future, when adding new attributes, problems may arise (for example, you named your attribute content, and then an attribute with the same name was entered into the spec as new and meaning something completely different)
  • data attributes have a wider DOM API for JavaScript

E
Evgeny Popov, 2013-11-28
@Kaaboeld

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.

D
Dennis Leukhin, 2013-11-28
@stonedmind

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 question

Ask a Question

731 491 924 answers to any question