HTML <data> data tag
The <data>
tag in HTML is used to associate a piece of content with a machine-readable value. It provides a way to encode information in a format that can be understood by both humans and machines. The <data>
tag is particularly useful for providing additional data alongside human-readable text, which can be accessed and utilized by scripts and other applications.
Syntax:
<p>The price of the item is <data value="19.99">19.99 USD</data>.</p>
Key Characteristics:
Machine-Readable Data: The
<data>
tag allows you to specify a machine-readable value using thevalue
attribute. This value can be used by scripts or other systems to process or analyze the data more effectively.Human-Readable Content: The content between the opening and closing
<data>
tags is the human-readable text. This is what users see on the web page.Attribute: The
value
attribute is used to provide the machine-readable data. This can be a number, date, or any other value that represents the content.
Example Usage:
Basic Example:
<p>The price of the item is <data value="19.99">19.99 USD</data>.</p>
In this example:
- The
value
attribute contains the machine-readable value19.99
, which represents the price. - The text
19.99 USD
is displayed to users.
Example with Date:
<p>Event date: <data value="2024-09-15">September 15, 2024</data>.</p>
In this example:
- The
value
attribute contains the machine-readable date2024-09-15
. - The text
September 15, 2024
is displayed to users.
CSS Styling:
The <data>
tag can be styled using CSS like any other HTML element. For example:
<style>
data {
font-weight: bold;
color: #333;
}
</style>
This CSS will apply bold styling and a color to the <data>
element.
Accessibility and SEO:
- Accessibility: The
<data>
tag improves accessibility by providing machine-readable values that can be used by assistive technologies and scripts. However, since the primary purpose of the<data>
tag is for encoding data, it should be used in contexts where this additional information is useful and necessary. - SEO: While the
<data>
tag itself does not directly impact SEO, it helps provide structured data that could be utilized by search engines or other applications. For more structured data and SEO purposes, consider using schema markup (e.g., JSON-LD) which is specifically designed for search engines.