The data-something attribute in HTML refers to custom data attributes, which are attributes that start with data- and are used to store extra information on HTML elements. These attributes are not displayed to the user but can be accessed via JavaScript or used for styling with CSS selectors in some cases.
<div data-user-id="12345" data-role="admin">John Doe</div>
In this example:
data-user-id and data-role are custom data attributes.data-.const element = document.querySelector('div');
console.log(element.dataset.userId); // "12345"
console.log(element.dataset.role); // "admin"
Note: The
datasetproperty returns alldata-*attributes as a JavaScript object, and the names are converted to camelCase.
data-* Attributes?They should not be used for storing sensitive data, or replacing proper APIs, JSON data models, or database storage.
Let me know if you want a practical example or use case.