HTML <data> Tag

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 4 Examples
Text & Semantics

What You’ll Learn

By the end of this tutorial, you’ll link human-readable labels to machine-readable values with the <data> element.

01

Data Syntax

Pair visible text with the required value attribute.

02

Machine Values

Store numbers, codes, and strings scripts can read.

03

Element vs Attribute

Distinguish <data> from data-* custom attrs.

04

JavaScript Access

Read and update values with the .value property.

05

data vs time

Know when to use time for dates instead.

06

CSS Styling

Style visible labels with classes on the element.

What Is the <data> Tag?

The data element (<data>) links human-readable text to a machine-readable value using the value attribute. Readers see the element’s text; scripts read .value through the HTMLDataElement interface.

💡
Not the same as data-* attributes

<data> is an HTML element with visible content. data-* attributes are custom metadata on any element, accessed via element.dataset.

Common uses include temperatures, prices, product ratings, inventory counts, or any value where the displayed text differs from the machine-readable form scripts need.

📝 Syntax

Wrap visible text in <data> and set the machine-readable form in value:

syntax.html
<data value="42">forty-two</data>

Syntax Rules

  • The value attribute is required and holds the machine-readable string.
  • Text content is what users see on the rendered page.
  • <data> is an inline phrasing element—it nests inside paragraphs and lists.
  • Use <time datetime> for dates and times instead of generic data.

⚡ Quick Reference

FeatureSyntax / RuleNotes
Required attrvalueMachine-readable string
DisplayText contentHuman-readable label on page
Element typeInlinePhrasing content
JS accesselement.valueHTMLDataElement property
Not the samedata-*Custom attrs on any element
vs timeGeneral purposetime is for dates/times only

⚖️ <data> Element vs data-* Attributes

These share a name but serve different purposes in HTML:

Feature<data> elementdata-* attributes
What it isHTML tag with visible textCustom metadata on any element
Example<data value="4.5">4.5 stars</data><div data-price="19.99">
JS accesselement.valueelement.dataset.price
Visible?Yes — text content rendersNo — attribute only

🧰 Attributes

The value attribute is required. Global attributes also apply:

value Required

Machine-readable form of the content—what scripts read via .value.

value="42"
class Global

CSS hook for styling the visible label text.

class="price-tag"
id Global

Unique identifier for JavaScript selection and updates.

id="stock-price"
style Global

Inline presentation on the visible text (prefer CSS classes).

style="color:#0f766e"
title Global

Tooltip on hover for extra context about the value.

title="Celsius"
data-* Optional

Extra custom metadata alongside value if needed.

data-unit="celsius"

Example: <data value="2024" class="highlight-year" id="year-data">Important Year</data>

Examples Gallery

Basic values, measurements, JavaScript updates, and data element vs data-* attributes with copy-ready code and live previews.

Live Preview

Readers see the label; scripts can read value="25":

Temperature:25°C

Basic value Attribute

Pair a numeric machine value with human-friendly text.

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

📚 Common Use Cases

Use <data> for temperatures, prices, product ratings, inventory counts, or any value where the displayed text differs from the machine-readable form scripts need.

Measurement with Machine Value

Store the numeric value separately from the formatted display.

temperature-data.html
<p>
  The average temperature today is
  <data value="25">25°C</data>.
</p>
Try It Yourself

JavaScript and data.value

Read and update the machine-readable value with JavaScript while keeping the display in sync.

data-javascript.html
<data id="stock-price" value="150">$150</data>

<script>
  var stock = document.getElementById("stock-price");
  var price = Number(stock.value) + 10;
  stock.value = String(price);
  stock.textContent = "$" + price;
</script>
Try It Yourself

data Element vs data-* Attributes

Do not confuse the <data> tag with custom data-* attributes on other elements.

data-vs-data-attr.html
<!-- data ELEMENT -->
<data value="4.5">4.5 stars</data>

<!-- data-* ATTRIBUTE on a div -->
<div data-sku="BK-1024" data-price="19.99">Notebook</div>
Try It Yourself

Styling <data> with CSS

The visible label is styled like any inline text. Use classes to highlight prices, measurements, or ratings:

font-weight Emphasize values
color Brand accent
background Chip-style labels
font-variant-numeric Tabular numbers
data-styles.css
/* Price highlight on data element */
data {
  font-weight: 600;
}

.price-tag {
  color: #15803d;
  background: #ecfdf5;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.measurement {
  color: #0f766e;
  font-variant-numeric: tabular-nums;
}

Live styled data values

♿ Accessibility

The value attribute is primarily for scripts, not screen readers:

  • Make text content meaningful — users and assistive tech read the visible text.
  • Do not hide important info in value only — put readable text inside the element.
  • Use time for dates — when content is a date/time, time may be more semantic.
  • Keep value accurate — scripts rely on it for calculations and sorting.

🧠 How <data> Works

1

Author adds data with value

Human text inside the tag; machine form in value.

Markup
2

Browser renders text content

Users see the label, not the raw value attribute.

Display
3

JavaScript reads .value

Scripts access the machine-readable form for logic and updates.

Scripting
=

Rich, scriptable content

Friendly labels for humans, structured values for code.

Modern Browser Support

The <data> element is fully supported in all modern browsers. Internet Explorer does not support it—use a span with data-* attributes as a fallback if IE support is required.

HTML5 · Since 2012

Machine-readable values in modern browsers

Chrome, Firefox, Safari, Edge, and Opera all support the data element. Legacy IE requires a fallback pattern.

98% Modern browser support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer Not supported · Use span fallback
Not supported
Opera All modern versions
Full support
<data> tag 98% supported

Bottom line: Safe for all modern production environments. For legacy IE, fall back to <span data-value="..."> with equivalent JavaScript.

Conclusion

The <data> tag connects human-readable labels to machine-readable values through the value attribute. Use it for measurements, prices, and ratings—and remember it is not the same as data-* custom attributes on other elements.

💡 Best Practices

✅ Do

  • Always set the value attribute
  • Keep visible text meaningful for readers
  • Use .value in JavaScript for logic
  • Use time for date/time content

❌ Don’t

  • Confuse data element with data-* attrs
  • Confuse data with datalist
  • Hide important info only in value
  • Omit readable text inside the element

Key Takeaways

Knowledge Unlocked

Six truths every developer should know about <data>

Bookmark these before you ship — they’ll keep your machine-readable markup clean and correct.

6
Core concepts
👁 02

Visible Text

Text content is what users see on the rendered page.

Essential
🔗 03

Not data-*

Element tag ≠ custom data-* attributes on any element.

Reference
04

JavaScript .value

Read and update machine values through HTMLDataElement.

Scripting
05

Valid HTML5

Inline phrasing element supported in all modern browsers.

Syntax
🕑 06

Use time for dates

Prefer <time datetime> for date/time content.

Pattern

❓ Frequently Asked Questions

It links visible text to a machine-readable value that scripts can read via the element’s .value property.
No. <data> is an HTML element. data-* attributes are custom attributes on any element, accessed via dataset.
Yes. The value attribute provides the machine-readable form and is essential to the element’s purpose.
Select the element and use element.value to get or set the machine-readable string.
time is for dates and times with datetime. data is general-purpose for any machine-readable value.

Practice Machine-Readable Values

Try the value attribute and JavaScript .value in the interactive editor.

Try JavaScript data →

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.

6 people found this page helpful