HTML: Custom Data Attribute
What is Custom Data Attribute
Custom Data Attribute are user-defined attribute of HTML element.
The attribute's name must start with data-
.
A custom data attribute is an attribute in no namespace whose name starts with the string "data-", has at least one character after the hyphen, is XML-compatible, and contains no ASCII upper alphas.
[2020-04-20 from https://html.spec.whatwg.org/multipage/dom.html#custom-data-attribute]
Example of Custom Data Attribute
example of adding accessed date of a url as data attribute.
<a href="http://example.com/some" data-accessed="2025-03-07">http://example.com/some</a>
Using JavaScript to Access Custom Data Attribute
You can use JavaScript DOM getAttribute
method, like any other attribute.