When I used HTML4 and its "ancestors" so to speak I used to declare non-existent attributes that syntactically presented no error, but semantically.
W3C realized that there were many cases in which these statements left the html polluted and therefore created the data-whatever.
Example:
If you were to define an input, usually the behavior of it, by default it would just have a value.
Now, if you had a menu, and you need to define multiple behaviors, you could declare them like this:
data-toggle="true"
data-width="500"
data-height="200"
data-resize="true"
Another cool thing, and that developers used to use input type='hidden'
to store values so that nobody could access them, today you could already put them in the same input by inserting data-valor
, these two cases are used in a number of frameworks and plugins, what they bring with them and more semantics and reliability in terms of conflict with existing attributes.
Compatibility Can I Use data-