HTML <data> Tag

Beginner
5 min read
Updated: Oct 2026
4 examples
Live preview

Definition and Usage

The <data> element links human-readable content to a machine-readable form. Put the text people should see inside the tag, and put the coded form in the value attribute.

Use it for product IDs, codes, or other strings scripts can parse. If the content is a date or time, use <time> instead (MDN / HTML spec).

Baseline · Widely available.

Not deprecated. Widely available across browsers since about October 2017.

Not the same as data-*.

<data> is an element with value. Custom data-* attributes can go on any element and are a different feature.

HTML Syntax

syntax.html
<data value=" machine-value">readable text</data>

Both start and end tags are required. Content is phrasing content. The DOM interface is HTMLDataElement; scripts can read element.value.

Attributes

The attribute that defines <data>:

AttributeDescriptionTry it
valueMachine-readable translation of the element’s content (required for the element’s purpose)Try it

Global Attributes

The <data> tag also supports the Global Attributes in HTML.

Live Preview

Pick a product. The page shows the label; value holds the ID for machines.

A real <data>. Humans see the name; value stores the ID.

Product

New product:Mini Ketchup

value="398" — text content "Mini Ketchup"

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Basic value

Show readable text and store a coded form in value.

HTML
<p>
  The answer is
  <data value="42">forty-two</data>.
</p>
Try It Yourself

How It Works

  1. Open <data> and set value to the machine form.
  2. Write the human text between the tags.
  3. Close with </data>. Both tags are required.
  4. Render. The page shows the text; value stays available in the DOM.

Example 2 — Product Names with IDs

Associate each label with a stable product number (MDN-style pattern).

HTML
<p>New products:</p>
<ul>
  <li><data value="398">Mini Ketchup</data></li>
  <li><data value="399">Jumbo Ketchup</data></li>
  <li><data value="400">Mega Jumbo Ketchup</data></li>
</ul>
Try It Yourself

How It Works

  1. List each product with a readable name as content.
  2. Put the ID in value (stable for carts, APIs, or scripts).
  3. Keep names human-friendly — users never need to see the ID.
  4. Optional: CSS can show attr(value) for demos; that is styling, not required HTML.

Example 3 — Friendly Label, Exact Value

Display a formatted reading while storing a plain number for scripts.

HTML
<p>
  Average temperature:
  <data value="25">25&deg;C</data>.
</p>
Try It Yourself

How It Works

  1. Choose a parseable value (here a plain number).
  2. Show a friendly string with units or formatting as content.
  3. Read in JS with element.value when you need the coded form.
  4. Do not confuse with <meter> — meter is for a known range gauge UI.

Example 4 — Prefer <time> for Dates

Use <data> for codes; use <time> when the content is a date or time.

HTML
<!-- Codes / IDs: data -->
<p>SKU: <data value="SKU-1042">Blue Mug</data></p>

<!-- Dates / times: time -->
<p>Ships on
  <time datetime="2026-11-01">November 1, 2026</time>.
</p>
Try It Yourself

How It Works

  1. Pick the element by meaning. IDs and codes → <data>.
  2. Dates and times → <time datetime="…">.
  3. Keep human text readable in both cases.
  4. Follow the spec. MDN: if the content is time-related, you must use <time>.

Edge Cases & Pitfalls

Most mistakes mix up data, data-*, and time.

semantics

Dates belong in <time>

Do not use <data> for calendar dates or clock times. Use <time> with datetime.

naming

<data> ≠ data-*

Custom attributes like data-price are unrelated. See data-*.

value

Empty or missing value

Without a useful value, prefer a normal phrase element. The point of <data> is the machine translation.

a11y

Visible text still matters

Screen readers use the content, not a hidden ID. Keep the text clear; do not put the only meaningful label only in value.

js

Read .value, not inventing APIs

HTMLDataElement.value mirrors the attribute. That is not the same as dataset on other elements.

Browser Support

The <data> element is standard HTML. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

<data>

Widely available since about October 2017. Chrome, Firefox, Safari, Edge, and Opera support the element and HTMLDataElement.value.

96% Global support (approx.)
Google Chrome 62+
Full support
Mozilla Firefox 22+
Full support
Apple Safari 10+
Full support
Microsoft Edge 14+
Full support
Opera 49+
Full support
Samsung Internet 8+
Full support
Internet Explorer No
Not supported
<data> Widely supported

Bottom line: Safe for modern sites. Internet Explorer has no support — pair with plain text fallbacks only if you still target IE.

Key Takeaways

  • Role: human text inside; machine form in value.
  • Dates: use <time>, not <data>.
  • Naming: <data> ≠ data-* attributes.
  • JS: read HTMLDataElement.value when you need the coded form.

One line: <data value="…"> shows people a label and gives machines a parseable value.

Default CSS Settings

Browsers treat <data> like ordinary phrasing content. There is no special default look:

default.css
data {
  display: inline;
}

Add your own styles only if you need a visual cue. Keep focus and contrast accessible if you make it interactive later.

Frequently Asked Questions

The data element links human-readable text to a machine-readable form with the value attribute. Users see the text content; scripts can read the value.
No. The data element is a specific tag with a value attribute. data-* attributes are custom attributes you can add to any element (for example data-id) and read via element.dataset.
Yes for its purpose. value holds the machine-readable translation of the content. Without it, use a normal phrasing element instead.
If the content is a date or time, use the time element with datetime. Use data for other machine-readable strings such as product IDs or numeric codes.
Select the element and use its value property from HTMLDataElement, for example document.querySelector("data").value.
No. By default it looks like ordinary inline text. Add CSS only if you need a visible cue for learners or your design.

Next: datalist

Provide autocomplete-style suggestions for input fields.

datalist tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful