Favorites

DOM HTMLElement.dataset Property

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
HTMLElement.dataset
DOM HTMLElement PropertyThis property is supported by all modern browsers.
Updated 28th November 2026

The dataset property gives easy access to an element's data-* attributes, as an object with camelCase property names.

Description

The dataset property provides read and write access to the element's custom data attributes (data-*). The data- prefix is removed and dashed names become camelCase: data-user-id is dataset.userId. Values are always strings. Adding a property creates the attribute, and delete removes it.

Data attributes are a good way to pass information from your HTML to your JavaScript, such as IDs, settings or state, without inventing non-standard attributes. They're also visible to CSS, so [data-state="open"] selectors can style elements based on the same values your script changes.

Because values are strings, convert them when needed: Number(el.dataset.count) or el.dataset.enabled === 'true'. Store small pieces of data only; for larger objects, keep the data in JavaScript and store a key in the attribute.

Syntax

element.dataset
element.dataset.name = value

Value

A DOMStringMap of the element's data-* attributes, with names in camelCase.

Example

<div id="card" data-user-id="42" data-role="admin">User</div>
const card = document.getElementById('card');
console.log(card.dataset.userId, card.dataset.role);
card.dataset.status = 'active';
delete card.dataset.role;
console.log(card.outerHTML);

Browser Support

The following information will show you the current browser support for the HTMLElement.dataset property. Hover over a browser icon to see the version that first introduced support for this property.

This property is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee