HTML Data Attributes.
Data attributes (data-*) allow you to store extra, custom information directly on HTML elements. This data can then be easily accessed using CSS or JavaScript.
The Essentials
Data attributes always start with the prefix 'data-'.
They are used to store data that is private to the page or application.
Any attribute name can be used as long as it follows the data-* format.
They provide a way to link data to specific UI elements without using non-standard attributes.
JavaScript can access these via the 'dataset' property.
CSS can target elements based on these attributes using attribute selectors.
Professional Insights
JavaScript Integration
Styling with Data Attributes
Data vs. Hidden Inputs
SEO and Accessibility Note
Critical Pitfalls
Using uppercase letters in data attribute names (they will be converted to lowercase).
Storing sensitive information (like passwords) in data attributes—anyone can see them in the source.
Overusing them for styling when a simple class would be more performant.
Forgetting the 'data-' prefix.