Custom Data Attributes data-*
Store custom data directly on elements with data-* attributes.
What Are data-* Attributes?
Custom data attributes let you store extra information directly on HTML elements:
<button data-user-id="42" data-action="delete">Delete User</button>
<li data-category="frontend" data-level="beginner">HTML</li>
<!-- Format: data-[name]="value" -->
<!-- Any alphanumeric name after data- is valid -->
<!-- Values are always strings -->Why data-* Exists
Before data-*, developers stored extra data in:
- Hidden inputs (messy)
- CSS class names (fragile)
- Non-standard attributes like
relortitle(invalid HTML)
HTML5 formalized data-* as the official way to embed custom data without affecting semantics or presentation.
All lessons in this course
- id class style and title
- The hidden Attribute
- tabindex and accesskey
- Custom Data Attributes data-*