Use `dataset` to attach small amounts of application metadata to an HTML element without inventing new attributes. It exposes the element’s `data-*` attributes as string-valued properties: `data-user-name` becomes `dataset.userName`. Changes work both ways—setting a dataset property updates the attribute, and changing the attribute updates the dataset value. section 6.2.11 section 6.2.8
Set a behavior hook
```js const button = document.createElement("button"); button.dataset.action = "save"; button.innerText = "Save"; document.body.append(button); console.log(button.dataset.action); // "save" ``` The assignment also sets `data-action` on the button. That attribute is visible in DevTools. section 6.2.1 section 6.2.11
Keep the metadata contract small:
- Use data attributes for IDs, behavior hooks, flags, or tiny configurations. Values remain strings; keep complex state in memory rather than storing large JSON blobs in markup. section 6.2.11
- For a custom element’s core configuration, prefer standard attributes such as `variant` or `size`. Reserve `data-*` for application-specific metadata such as `data-product-id`; access standard custom-element attributes with `getAttribute` and `setAttribute`. section 7.9.1
