Table of Content
The data tag connects visible content with a machine-readable value in HTML. This helps browsers and tools understand and process the data.
Understand the HTML <data> Tag
The <data> tag links a machine-readable value with a human-readable label. It appears in lists and labels. Also, it appears in other places where visual content hides structured data.
Here is the syntax:
<data value="machine-readable-value">Human-readable label</data>The value attribute carries the raw data. The content between tags shows the text to users.
Use to store values that scripts or applications need. It helps browsers and crawlers find structured data. You can link a label with its actual data.
You place them inside lists or tables. It does not affect how the content looks.
The value attribute stores the real data. The browser does not display this value. It shows the text inside the <data> tag instead.
Scripts or crawlers read the value attribute. They use it to sort or filter structured content.
The content between tags shows a readable label. The value attribute gives the machine a structured format.
For example:
<data value="199.99">$199.99</data>The label uses currency symbols. The value keeps the number raw for scripts.
The Difference Between <data> and <span>
It pairs a visible label with a hidden value. only controls how content looks. Helps crawlers read content. Does not support machine-readable values.
Here is a table that shows you the key differences:
| Feature | ||
|---|---|---|
| Semantics | Adds machine-readable value | No semantics |
| Use case | For data extraction | For inline styles only |
| Attribute support | Supports value attribute | No built-in value support |
| Machine readability | Yes | No |
Here is the use case:
- Use it to store prices, IDs, timestamps, or values in lists.
- Use it to apply styles or layout adjustments.
Styles of the <data> Tag with CSS
You can style it like any inline element.
For example:
<style>
data {
color: #2a2a2a;
font-weight: bold;
background-color: #f0f0f0;
padding: 4px;
}
</style>This sets font and background for any <data> tag on the page.
Examples of <data> tag in HTML
Use to Show Price With Value:
<data value="45.99">$45.99</data>This shows the price to users but gives the raw float to JavaScript or search engines.
Show Dates in Readable Form:
<data value="2025-07-21">July 21, 2025</data>This gives the ISO date to crawlers. The label stays friendly for users.
Create a List of IDs With Labels:
<ul>
<li><data value="u001">User One</data></li>
<li><data value="u002">User Two</data></li>
</ul>This example maps user labels with machine-readable IDs. Scripts can fetch the value easily.
Filter Products by Script:
<div>
<data value="p23">Red T-Shirt</data>
<data value="p24">Blue T-Shirt</data>
</div>JavaScript uses the value attribute to group or sort products.
Wrapping Up
In this article, you learned how the <data> tag works and how to structure it correctly. You also saw how it differs from and how to style it.
Here is a quick recap:
- Use to pair a value with a label.
- Use the value attribute for machine-readable data.
- Style with normal CSS.
- Use only for inline styles.
FAQs
What does the <data> tag do in HTML?
Can I use CSS to style <data>?
How does <data> differ from <span>?
What value format should I use in <data value="">?
Similar Reads
The HTML bdi tag marks text that has an unknown or mixed direction. It makes sure that this part does…
The HTML class attribute helps group elements. It helps you update the page style without changing the structure of HTML.…
The HTML section tag groups parts of a web page that share one theme. It gives clear meaning to content.…
HTML global attributes work on most elements. They do not depend on the tag name. You can use them with…
The HTML <var> tag marks a word or phrase as a variable in a document. Web authors use it to…
HTML link attributes tell the browser how a link works. They set where the link goes, how it opens, and…
The HTML noscript tag tells the browser what to show when JavaScript does not run. This tag targets users who…
Forms need instructions so users know what to enter. You use the HTML label tag to give names to input…
The style tag in HTML defines CSS inside a web page. Click to see how it works with syntax and…
The nav tag defines a navigation block in HTML. It holds main links to other parts of your site. Search…