<data> Machine-readable data

Ties visible content to a machine-readable value.

<data> pairs human-friendly content with a machine-readable value: a product code behind a product name, say, or a raw number behind a formatted price.

People read the text and scripts read the value. The value attribute is required. Dates and times have their own element, <time>.

The data element definition (opens in a new tab) pairs a machine-readable value with human-readable content. For dates and times, use the time element.

Syntax

<data value="machine-value">Visible text</data>

When to use it

<data> pairs friendly text for people with an exact value for software: a product list where a script sorts by the raw price, a review summary showing "four stars" with the value 4, a size chart pairing "Large" with a stock code, or a league table holding exact points.

For dates, times and durations, use time. For a gauge-style value within a range, meter shows it visually. Custom data-* attributes also store values for scripts, but they add no meaning; data says that this text and this value describe the same thing.

On its own, data does not create search engine structured data. Combined with microdata, though, the value becomes the property value, so you can attach a schema.org sku (opens in a new tab) or rating number to visible text. Keep values in one consistent machine format, such as 9.5 rather than "9,50 EUR", so every tool reads them the same way.

Attributes

AttributeWhat it does
valueThe machine-readable value (required).

Live example

Edit the code and watch the preview.

<ul>
  <li><data value="39-021">Blue mug</data> - <data value="9.5">$9.50</data></li>
  <li><data value="39-022">Red mug</data> - <data value="11">$11.00</data></li>
</ul>

More examples

Ratings with numeric values

Reviewers see star ratings written in words, while each data element stores the number. A script or a sorting tool could use the values without parsing the text. The list itself reads naturally for people.

<h2>Reader ratings</h2>
<ul>
  <li>Classic pancakes: <data value="5">five stars</data></li>
  <li>Banana pancakes: <data value="4">four stars</data></li>
  <li>Oat pancakes: <data value="3">three stars</data></li>
</ul>

Value used by microdata

With microdata, a data element's value attribute becomes the property value. Here the visible text says "Blue mug", while the itemprop takes the machine-readable stock code from value. The name and description come from ordinary text.

<div itemscope itemtype="https://schema.org/Product">
  <h2 itemprop="name">Blue mug</h2>
  <p>Stock code: <data itemprop="sku" value="39-021">39-021 (blue)</data></p>
  <p itemprop="description">A large mug for tea or coffee.</p>
</div>

Tip: Dates go in time. Everything else can use data.

Browser support

data is part of the HTML Living Standard and is supported by all current browsers. Internet Explorer never supported it, but the text still shows there as an unknown inline element. The value DOM property came later; see the data element support table (opens in a new tab).

Accessibility

Screen readers read the visible text and never the value, so the content has to make sense by itself. The W3C note Understanding Info and Relationships (opens in a new tab) explains why the visible text must carry the meaning.

Common mistakes

Wrong

<data>42</data>

Right

<data value="42">Forty-two</data>

A data element needs its value attribute.

Frequently asked questions

What is the data tag in HTML?

An element that wraps human-readable content and keeps a machine-readable equivalent in its required value attribute, for example <data value="398">Mini Ketchup</data>. <data> lets scripts read element.value to sort or filter lists. Dates and times are better served by <time>, which is specialised for that job.

What is the difference between the data element and data attributes?

Scope. The <data> element pairs one visible piece of content with one value that belongs to the document's meaning. data-* attributes go on any element and hold private, custom information for your own scripts and styles. App state goes in data-*, and content values like product codes go in data. The global attributes page covers custom attributes.

Related text elements

<p>One paragraph of text.<br>Breaks the line inside text, as in a postal address or a poem.<hr>A change of topic between paragraphs, drawn as a horizontal line.<pre>Shows text exactly as typed, spaces and line breaks included.<blockquote>A longer quotation from another source, set apart as its own block.<div>A generic block box with no meaning, for grouping and styling.<span>A generic inline wrapper with no meaning, for styling part of a line of text.<strong>Text that is important, serious or urgent. Shown in bold by default.<em>Stress emphasis that changes what a sentence means. Italic by default.<b>Makes text stand out without adding importance, as with keywords. Bold by default.<i>Text in another voice: foreign words, terms, thoughts, ship names. Italic.<u>Text with an unspoken annotation, such as a flagged spelling error.<s>Content that is no longer accurate or relevant, drawn crossed out.<mark>Highlighted text, like a marker pen, showing relevance in the current context.<small>Side comments and fine print, like copyright lines or legal notes.<sub>Subscript text, set below the line, as in H2O.<sup>Superscript text, set above the line, as in exponents or 1st.<code>A fragment of computer code, set in a monospace font.<kbd>Keys or text the user should press or type.<samp>Sample output from a program or a computer system.<var>A variable in math or in code. Italic by default.<q>A short quotation inside a sentence. The browser adds the quote marks.<cite>The title of a creative work: a book, film, song, game or article.<abbr>An abbreviation or acronym, with an optional expansion in title.<dfn>Marks the term that the surrounding sentence or paragraph defines.<time>Marks a date, time or duration and gives it a machine-readable value.<del>Text that was removed from the document. Struck through by default.<ins>Text that was added to the document. Underlined by default.<wbr>A spot where the browser may break a long word if it has to.<bdi>Isolates text of unknown direction, such as user names.<bdo>Forces a text direction and overrides the normal bidi algorithm.<ruby>Small annotations above or beside text, mostly for East Asian pronunciation.<rt>The small reading or note in a ruby annotation.<rp>Fallback brackets around ruby text, shown only where ruby is unsupported.