Open In App

HTML data Tag

Last Updated : 28 Nov, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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>

HTML <data> Tag – FAQs

What attributes does the <data> tag support?

The <data> tag primarily supports the value attribute, which holds the machine-readable data associated with the content inside the tag.

When should I use the <data> tag?

Use the <data> tag when you need to associate a human-readable content string with a specific value that may be used in calculations, scripts, or other processing.

How is the <data> tag different from the <span> tag?

Unlike <span>, the <data> tag is semantically meaningful because it associates content with machine-readable data via the value attribute, whereas <span> is purely presentational.

Can I use the <data> tag within forms?

While the <data> tag can be used within forms, it does not directly contribute to form submissions. Use hidden inputs for submitting machine-readable data.

Can the <data> tag be styled using CSS?

Yes, like any inline element, the <data> tag can be styled using CSS to control font, color, and other visual properties.



Next Article

Similar Reads

three90RightbarBannerImg
  翻译: