Reputation: 21
I was reading on the W3C school website about the data-*
attribute and I read this:
"The data-* attributes is used to store custom data private to the page or application. The data-* attributes gives us the ability to embed custom data attributes on all HTML elements."
What does "custom data" mean in this context?
Upvotes: 0
Views: 637
Reputation: 157048
Beyond the available attributes in the specification, you might need additional information to store on elements. Before, people made up their own attribute names and put that in the tag, but that gave problems when validating the HTML for example.
Nowadays, there is a standard to provide 'custom' attributes, the data-
attributes. This way the validator knows what to do, and you as a developer has the freedom to add attributes if you need them.
Old invalid syntax sample (does not validate!):
<input somevariable="somevalue" />
New and improved and perfectly valid due to the data-
prefix:
<input data-somevariable="somevalue" />
Upvotes: 1