This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2018.
The dataset read-only property of the SVGElement interface provides read/write access to custom data attributes (data-*) on elements. It exposes a map of strings (DOMStringMap) with an entry for each data-* attribute.
For more information on the behavior of dataset, see HTMLElement.dataset.
A DOMStringMap.
<div>
<svg viewBox="0 0 120 30" xmlns="http://www.w3.org/2000/svg">
<text x="20" y="20" id="user" data-id="1234567890" data-user="carinaanand">
Carina Anand
</text>
</svg>
</div>
const el = document.querySelector("#user");
console.log(el.dataset.id); // "1234567890"
| Specification |
|---|
| HTML> # dom-dataset-dev> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
dataset |
55 | 17 | 51 | 41 | 5.1 | 55 | 51 | 41 | 5 | 6.0 | 55 | 5 |
data-* SVG attributes
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/SVGElement/dataset