<data>

HTML <data> Tag

The <data> tag is a new element in HTML5. The tag is used to define a machine-readable analogue for the specified data (a standardized version, understandable to automated systems or scripts on the website).

This may be useful in cases when the data should be in a particular format necessary for running scripts, but you don’t want your users to see this format. For example, you want to display a list of products for your users to choose from. Each product has its ID, but you don’t want to show this information to your users. Then you place the product IDs in the <data> tag, and the machine will process this information and show users the product with the corresponding ID.

You can access data attributes from CSS, as they are simple HTML attributes. Data attributes can be stored to include constantly changing information. (您可以从CSS访问数据属性,因为它们是简单的HTML属性。可以存储数据属性,以包括不断变化的信息。)

The content which must be accessible and visible in data attributes should not be stored, since assistive technology may not access them. Besides, the values of the data attributes may not be indexed by search crawlers. (必须在数据属性中可访问和可见的内容不应存储,因为辅助技术可能无法访问它们。此外,数据属性的值可能不会被搜索爬虫索引。)

We recommend to use the <time> tag. If the value is date or time related.

Syntax

Syntax (语法)

The <data> tag comes in pairs. The content is written between the opening (<data>) and closing (</data>) tags.

Example of the HTML tag:

<!DOCTYPE html>
<html>
 <head>
   <title>Title of the document</title>
 </head>
 <body>
   <p>Refrigerated drinks</p>
   <ul>
     <li>
       <data value="1545325112">Coca-Cola 500ml</data>
     </li>
     <li>
       <data value="1545325113">Coca-Cola 330ml</data>
     </li>
     <li>
       <data value="1545325114">Coca-Cola Light 330ml</data>
     </li>
   </ul>
 </body>
</html>

Result

Attributes

Attributes (属性)

AttributeValueDescription
valuemachine-readable formatSets the machine-readable version of the contents of the <data> tag.

The <data> tag also supports the Global Attributes and the Event Attributes.

How to style <data> tag? Common properties to alter the visual weight/emphasis/size of text in <data> tag:

CSS font-style property sets the style of the font. normal | italic | oblique | initial | inherit. CSS font-family property specifies a prioritized list of one or more font family names and/or generic family names for the selected element. CSS font-size property sets the size of the font. CSS font-weight property defines whether the font should be bold or thick. CSS text-transform property controls text case and capitalization. CSS text-decoration property specifies the decoration added to text, and is a shorthand property for text-decoration-line, text-decoration-color, text-decoration-style.

Coloring text in <data> tag:

CSS color property describes the color of the text content and text decorations. CSS background-color property sets the background color of an element.

Text layout styles for <data> tag:

CSS text-indent property specifies the indentation of the first line in a text block. CSS text-overflow property specifies how overflowed content that is not displayed should be signalled to the user. CSS white-space property specifies how white-space inside an element is handled. CSS word-break property specifies where the lines should be broken.

Other properties worth looking at for <data> tag:

CSS text-shadow property adds shadow to text. CSS text-align-last property sets the alignment of the last line of the text. CSS line-height property specifies the height of a line. CSS letter-spacing property defines the spaces between letters/characters in a text. CSS word-spacing property sets the spacing between words.



请遵守《互联网环境法规》文明发言,欢迎讨论问题
扫码反馈

扫一扫,反馈当前页面

咨询反馈
扫码关注
返回顶部