Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

HTML element: data

The data element pairs visible human-readable content with a corresponding machine-readable form chosen by the author.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

<data value="SKU-042">Blue mug</data>

data requires the value attribute; HTMLDataElement.value reflects it as a string and does not automatically parse an identifier, number, or other format.

When the value is a date or time, the appropriate element is time with datetime, not generic data.

The element is not a custom data-* attribute: those attributes populate dataset, whereas data semantically connects its own text to one value.

The example uses querySelectorAll() to count products, compares textContent with value, and checks that dataset remains empty.

Examples

<!doctype html>
<meta charset="utf-8">
<ul id="products">
  <li><data id="mug" value="SKU-042">Blue mug</data></li>
  <li><data value="SKU-107">Steel bottle</data></li>
</ul>
<output id="result"></output>
<script>
const products = document.querySelector("#products");
const mug = document.querySelector("#mug");
document.querySelector("#result").textContent = `items=${products.querySelectorAll("data").length}; machine=${mug.value}; human=${mug.textContent}; tag=${mug.tagName}; customData=${Object.keys(mug.dataset).length}`;
</script>

Result

items=2; machine=SKU-042; human=Blue mug; tag=DATA; customData=0

The result verifies two visible products and the first product’s SKU identifier; it does not validate uniqueness or the author’s value syntax.

Sources