The data-* global attributes let you store custom metadata on any HTML element. Any attribute whose name starts with data- is a custom data attribute — for example data-user-id or data-columns.
Use them when scripts or CSS need extra information that should not change how the element looks by default. Prefer them over inventing non-standard attributes. They are not the same as the data attribute on <object> (a resource URL).
Baseline · Widely available.
Not deprecated and not experimental. Stable HTML5 global attributes with broad browser support, including element.dataset.
Not for visible content or secrets.
Assistive tech and search engines may ignore data values. Keep user-facing text in real content. Never store passwords or tokens in data-*.
Syntax
HTML Syntax
syntax.html
<element data-name="value">
Use lowercase names with hyphens (data-user-id). Avoid names that start with xml, contain :, or use capitals. For dataset, prefer names that map cleanly to camelCase (avoid data-test-1).
Values
Attribute Values
Any string. The browser always stores the value as text:
Variant lives in data-.data-variant="note" or "warning".
CSS matches the value with [data-variant="…"].
JS can switch variants with el.dataset.variant = "warning" without juggling many class names.
Edge Cases & Pitfalls
Most mistakes come from treating data-* like secure storage or visible content.
a11y
Do not hide important text in data-*
Screen readers and crawlers may skip attribute values. Put real content in the element text (or use proper ARIA when needed).
security
Visible in source — no secrets
Anyone can view data-* in DevTools. Keep tokens and passwords off the page.
naming
dataset needs clean names
Avoid data-test-1 or data--x if you rely on dataset. Prefer data-test-one. Use getAttribute when names are awkward.
types
Everything is a string
dataset.count === 5 is false when the value is "5". Convert with Number(), parseInt(), or compare to "true" for flags.
compare
Not the object data attribute
data on <object> is a URL. data-* is custom metadata on any element.
Compatibility
Browser Support
data-* is an HTML global attribute family in the browser. It is not a Node.js, Deno, or Bun API.
✓ Baseline · Widely available
data-*
Custom data attributes and HTMLElement.dataset are widely supported in modern browsers. Safe to use for markup metadata and progressive enhancement.
97%Global support (approx.)
Google Chrome7+ · dataset 8+
Full support
Mozilla Firefox6+
Full support
Apple Safari5.1+
Full support
Microsoft Edge12+
Full support
Opera11.1+
Full support
Samsung InternetModern
Full support
Internet Explorer11 (dataset)
Supported
data-*Widely supported
Bottom line: Use data-* freely for client-side metadata. Prefer getAttribute if you must support very old browsers without dataset.
Remember
Key Takeaways
Role: store private string metadata on any element with a data- name.
JavaScript: read and write via element.dataset (kebab → camelCase).
CSS: select with [data-name="value"] when you need style hooks.
Safety: not for secrets; not a substitute for visible, accessible content.
One line:data-* is the standard way to attach custom string data to HTML for scripts and CSS.
Frequently Asked Questions
They are custom attributes whose names start with data-. You use them to store extra string metadata on any HTML element for scripts or CSS, without inventing non-standard attributes.
Use element.dataset. The part after data- is converted from kebab-case to camelCase — for example data-user-id becomes dataset.userId. You can also use getAttribute("data-user-id").
No. On <object>, data holds a resource URL. data-* custom attributes work on any element and store arbitrary metadata.
In the DOM they are always strings. Store numbers or JSON as text, then parse them in JavaScript (Number(), JSON.parse(), and so on).
No. They appear in the HTML source and DevTools. Never store passwords, tokens, or other secrets there.
data-* and HTMLElement.dataset are Baseline widely available. Modern Chrome, Firefox, Safari, and Edge all support them; Internet Explorer supports dataset from IE 11.