What is Data Attributes in HTML ?
|some value||Speciﬁes the value of the attribute (as a string)|
Section 11.1: Older browsers support
Data attributes were introduced in HTML5 which is supported by all modern browsers, but older browsers before HTML5 don’t recognize the data attributes.
However, in HTML speciﬁcations, attributes that are not recognized by the browser must be left alone and the browser will simply ignore them when rendering the page.
Web developers have utilized this fact to create non-standard attributes which are any attributes not part of the HTML speciﬁcations. For example, the value attribute in the line bellow is considered a non-standard attribute because the speciﬁcations for the <img>tag don’t have a value attribute and it is not a global attribute:
<img src="sample.jpg" value="test" />
Section 11.2: Data Attribute Use
<div data-submitted="yes" class="user_profile"> … some content … </div>
- Data attribute structure is data-*, i.e. the name of the data attribute comes after the data- part. Using this name, the attribute can be accessed.
- Data in string format (including json) can be stored using data-* attribute.