🚀 Levoric Learn v2.1.1: Improved tutorials, faster navigation, and more. Learn more

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

AttributesDescription
accesskeySpecifies a shortcut key to activate or focus an element.
autocapitalizeControls whether and how text input is automatically capitalized.
classSpecifies one or more class names for the element, allowing CSS styling and JavaScript manipulation.
contenteditableSpecifies whether the content of an element is editable or not.
contextmenuSpecifies a context menu for the element.
dirDefines the text direction. Possible values are "ltr" (left-to-right), "rtl" (right-to-left), and "auto".
draggableSpecifies whether an element is draggable. Possible values are "true" or "false".
enterkeyhintSpecifies the action label or icon to be shown for the enter key on virtual keyboards.
hiddenIndicates that the element is not yet, or is no longer, relevant. The browser does not display elements that have the `hidden` attribute set.
idSpecifies a unique identifier for the element.
inputmodeProvides a hint to browsers for which virtual keyboard configuration to use when editing this element or its descendants.
isAllows you to specify the type of custom element.
langSpecifies the language of the element's content.
nonceA 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.
partSpecifies the element’s part in the shadow DOM.
slotAssigns a slot in a shadow DOM shadow tree.
spellcheckIndicates whether the element is subject to spell checking.
styleProvides inline CSS styling for the element.
tabindexSpecifies the tab order of the element.
titleAdds extra information about the element, displayed as a tooltip when hovering over the element.
translateSpecifies whether the content of the element should be translated. Possible values are "yes" or "no".
HTML AttributesGlobal AttributesEvent Attributes
To view the full list
To view the full list
To view the full list
elementsChrome BrowsersMicrosoft Edge BrowserFirefox BrowsersSafari BrowserOpera Browser
<data>62.013.022.0No49.0