HTML Reference ยท Inline Text
The <data> element
Reference for the HTML <data> element: pairing human-readable text with a machine-readable value, reading it from JavaScript, and when to use <time> instead.
The <data> element links a piece of content to a machine-readable value. People read the text inside the element; scripts, search engines and other tools read the value attribute. It is useful for product codes, IDs, prices or numbers that appear in a friendly format on the page.
For dates and times, use <time> instead, which has its own datetime attribute and rules.
<data value="8712345678906">Oat milk, 1 litre</data>
Try it
The text is written for people, but the script sorts reliably by reading value through the HTMLDataElement.value property.
Attributes
| Attribute | Values | Description |
|---|---|---|
value |
Text | Required. The machine-readable form of the element's content. |
The element also accepts the global attributes.
Usage notes
valueis required. A<data>withoutvalueis invalid; there would be nothing for machines to read.- Choose a stable format. Use a consistent, unambiguous format in
value: plain numbers with a dot as decimal separator, ISO codes, product identifiers. <data>vsdata-*attributes.data-*attributes store private values for your own scripts on any element.<data>exposes a value that is part of the content and meant to be understood by other tools too, for example in microdata.- Not for dates. Use
<time>for dates, times and durations. - Accessibility. Only the visible text is read aloud. Make sure it is meaningful on its own.
Technical summary
| Content categories | Flow content, phrasing content, palpable content |
| Permitted content | Phrasing content |
| Tag omission | None; both the start and end tags are required |
| Permitted parents | Any element that accepts phrasing content |
| Implicit ARIA role | generic |
| DOM interface | HTMLDataElement |
| Default display | inline |
Browser support
Supported in all current browsers.
Related
<time>โ dates, times and durations<meter>โ a value within a known range- Global attributes โ including
data-* - Lessons: Times, Data Values and Ruby Text, Custom Data Attributes, Structured Data