HTML: Custom Data Attribute

By Xah Lee. Date: . Last updated: .

What is custom data attribute

Custom Data Attribute are user-defined attribute of HTML element.

The attribute's name must start with data-.

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.

Reference

html custom data attribute 2026-08-04 ll
html custom data attribute 2026-08-04 ll

HTML custom tags and attribute