Skip to main content

HTML Tags

HTML <data> Tag

Written by Updated HTML <data> Tag exercises

The data tag pairs what people read with what programs need. Readers see "₹599", and a script or a search engine gets the plain number 599 from the value attribute.

That matters because display text is messy for computers. "₹599", "Rs. 599" and "599 rupees" all mean the same price, but a script sorting products cannot easily read any of them. <data> keeps the friendly text and adds a clean value next to it.

Syntax

html

<data value="machine-readable-value">Human-readable text</data>
AttributeWhat it does
valueThe machine-readable version of the content. Required.

You can also use the global attributes, such as class and id.

Example

html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>HTML data Tag Example</title>
</head>
<body>
  <h2>HTML &lt;data&gt; Tag Example</h2>

  <p>The price of the product is <data value="599">₹599</data>.</p>
  <p>My birth year is <data value="1990">1990</data>.</p>
</body>
</html>

The page shows ₹599 and 1990 as normal text. The values are not visible; they are there for code.

Reading the value with JavaScript

Sort or calculate with the clean value

html

<p>Price: <data id="price" value="599">₹599</data></p>

<script>
  const price = document.getElementById("price").value;  // "599"
  console.log(Number(price) * 2);                         // 1198
</script>

The value property returns a string, so convert it with Number() before doing math.

data or time?

For dates and times, use the time tag with its datetime attribute instead. <data> is for everything else: prices, product codes, scores, IDs.

Browser Support

Chrome
Edge
Firefox
Safari
Opera
IE9+
YesYesYesYesYesYes

Good to know

  • <data> does not change how text looks or behaves. It is an inline element with no default style.
  • Search engines may use the value, but <data> alone is not structured data. For rich results such as product prices in Google, you still need schema markup.
  • If there is no machine-readable value worth adding, plain text is fine. Do not wrap things in <data> just because you can.

HTML <data> Tag exercises

Attach a machine value

Show Widget with the value A1 for programs, using the element made for that.

Result

Check your answer to see it here.