Interview Question

What are data attributes?

A data-* attribute attaches simple custom information to an element.

💡 Concept ✅ Quick Revision 🌐 HTML

Answer

Data attributes store small custom values on an HTML element. • Their names begin with `data-`. • JavaScript reads them through `dataset`. • They should not store secret or large information.

💡 Simple Example

<button data-product-id="42">Buy</button>

⚡ Quick Revision

A data-* attribute attaches simple custom information to an element.