Copied successfully!
Introduction to <data>
tag
The <data>tag is a lesser-known but highly useful element in HTML. It allows developers to associate a specific piece of content with a machine-readable value, making it easier for web applications and search engines to understand and utilize the information, the <data>tag is particularly helpful in scenarios where human-readable text needs to be paired with a corresponding data value, like when displaying a product's name alongside its price or ID.
Copy to clipboard
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Table with Data Tag Example</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>Product Inventory Table with <code><data></code> Tag</h1>
<table>
<thead>
<tr>
<th>Product ID</th>
<th>Product Name</th>
<th>Price</th>
<th>In Stock</th>
</tr>
</thead>
<tbody>
<tr>
<td><data value="SKU001">P001</data></td>
<td>Smartphone</td>
<td><data value="599.99">$599.99</data></td>
<td>Yes</td>
</tr>
<tr>
<td><data value="SKU002">P002</data></td>
<td>Wireless Earbuds</td>
<td><data value="129.99">$129.99</data></td>
<td>No</td>
</tr>
<tr>
<td><data value="SKU003">P003</data></td>
<td>Laptop</td>
<td><data value="899.99">$899.99</data></td>
<td>Yes</td>
</tr>
<tr>
<td><data value="SKU004">P004</data></td>
<td>Tablet</td>
<td><data value="399.99">$399.99</data></td>
<td>Yes</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Copy to clipboard
/* General Styles for the body and container */
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; /* Font style */
background-color: #f0f0f5; /* Light gray background color */
color: #333; /* Text color */
margin: 0;
padding: 20px; /* Padding around the body */
}
.container {
max-width: 800px; /* Max width for the container */
margin: 0 auto; /* Center the container */
background-color: #fff; /* White background for the container */
padding: 20px; /* Padding inside the container */
border-radius: 8px; /* Rounded corners for the container */
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); /* Box shadow for depth */
}
h1 {
text-align: center; /* Center the heading text */
margin-bottom: 20px; /* Space below the heading */
color: #0073e6; /* Blue color for the heading */
}
/* Table Styles */
table {
width: 100%; /* Full width table */
border-collapse: collapse; /* Remove space between table borders */
margin-bottom: 20px; /* Space below the table */
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1); /* Box shadow for table */
background-color: #fafafa; /* Light background for the table */
border-radius: 8px; /* Rounded corners for the table */
overflow: hidden; /* Prevent overflow on rounded corners */
}
th, td {
padding: 12px 15px; /* Padding for table cells */
text-align: left; /* Align text to the left */
border-bottom: 1px solid #ddd; /* Bottom border for rows */
}
/* Header Styles */
thead th {
background-color: #333; /* Dark background for headers */
color: #fff; /* White text for headers */
text-transform: uppercase; /* Uppercase text for headers */
letter-spacing: 0.05em; /* Spacing between letters for headers */
}
/* Data Tag Styling */
td data {
font-weight: bold; /* Bold text for data tag */
color: #0073e6; /* Blue color for machine-readable data */
}
/* Alternate Row Background for Table Body */
tbody tr:nth-child(even) {
background-color: #f2f2f2; /* Light gray background for even rows */
}
/* Hover Effect for Table Rows */
tbody tr:hover {
background-color: #e0e0e0; /* Slightly darker background on hover */
cursor: pointer; /* Pointer cursor on hover */
}
Global Attributes
Attributes | Description |
---|---|
accesskey | Specifies a shortcut key to activate or focus an element. |
autocapitalize | Controls whether and how text input is automatically capitalized. |
class | Specifies one or more class names for the element, allowing CSS styling and JavaScript manipulation. |
contenteditable | Specifies whether the content of an element is editable or not. |
contextmenu | Specifies a context menu for the element. |
dir | Defines the text direction. Possible values are "ltr" (left-to-right), "rtl" (right-to-left), and "auto". |
draggable | Specifies whether an element is draggable. Possible values are "true" or "false". |
enterkeyhint | Specifies the action label or icon to be shown for the enter key on virtual keyboards. |
hidden | Indicates that the element is not yet, or is no longer, relevant. The browser does not display elements that have the `hidden` attribute set. |
id | Specifies a unique identifier for the element. |
inputmode | Provides a hint to browsers for which virtual keyboard configuration to use when editing this element or its descendants. |
is | Allows you to specify the type of custom element. |
lang | Specifies the language of the element's content. |
nonce | A cryptographic nonce ("number used once") that can be used by Content Security Policy (CSP) to determine whether or not a given fetch will be allowed to proceed. |
part | Specifies the element’s part in the shadow DOM. |
slot | Assigns a slot in a shadow DOM shadow tree. |
spellcheck | Indicates whether the element is subject to spell checking. |
style | Provides inline CSS styling for the element. |
tabindex | Specifies the tab order of the element. |
title | Adds extra information about the element, displayed as a tooltip when hovering over the element. |
translate | Specifies whether the content of the element should be translated. Possible values are "yes" or "no". |
HTML Attributes | Global Attributes | Event Attributes |
---|---|---|
To view the full list | To view the full list | To view the full list |
elements | |||||
---|---|---|---|---|---|
<data> | 62.0 | 13.0 | 22.0 | No | 49.0 |
Improve Our Platform
Did you find what you were looking for?
Learn how to contribute.Last updated on January 12, 2025by our contributors.
View this page on GitHub• Report an issue with this content