Open In App

HTML data Tag

Last Updated : 28 Nov, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The HTML <data> tag is used to link a piece of content with a machine-readable translation, making it easier for machines to interpret the data.

  • The content inside the tag is the text displayed to the user.
  • It does not affect the layout or visual display of the content.
  • It is useful for embedding structured data (like numbers and dates) without altering how the content is shown to the user.

Note: If the content is a date or time-related content, then use <time> element instead of the data element.

HTML
<!DOCTYPE html>
<html>

<body>
  <p>GeeksforGeeks Subject List:</p>
  <ul>
    <li>
      <data value="009">Data Structure</data>
    </li>
    <li>
      <data value="010">Algorithm</data>
    </li>
    <li>
      <data value="011">HTML</data>
    </li>
    <li>
      <data value="019">Operating System</data>
    </li>
    <li>
      <data value="110">Computer Network</data>
    </li>
    <li>
      <data value="111">DBMS</data>
    </li>
  </ul>
</body>

</html>

Syntax

<data value="10"> This sample paragraph </data>

Attributes

  • value: It contains a single machine-readable translation of the content.

Example 2

HTML
<!DOCTYPE html>
<html lang="en">

<head>
  <style>
    .product {
      margin: 10px 0;
      padding: 10px;
      border: 1px solid #ccc;
      border-radius: 5px;
    }

    .price {
      font-weight: bold;
      color: green;
    }
  </style>
</head>

<body>
  <h1>Product List</h1>
  <div class="product">
    <h2>Product A</h2>
    <p class="price">
      Price: <data value="100">₹100</data>
    </p>
  </div>
  <div class="product">
    <h2>Product B</h2>
    <p class="price">
      Price: <data value="150">₹150</data>
    </p>
  </div>
  <div class="product">
    <h2>Product C</h2>
    <p class="price">
      Price: <data value="300">₹300</data>
    </p>
  </div>
</body>

</html>

Next Article

Similar Reads