Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML data-* Attribute

HTML data-* Attribute

HTML Global Attributes HTML Global Attributes

Example

Using the data-* attribute to embed custom data:

Try it »


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the data-* attribute.


Definition and Usage

The data-* attribute is used to store custom data private to the page or application.

The data-* attribute allows data to be embedded in all HTML elements.

Custom data can give a page a better interactive experience (without the need to use Ajax or query the server for data).

The data-* attribute consists of two parts:

  1. The attribute name must not contain uppercase letters, and there must be at least one character after data-.
  2. The attribute can be any string

Note: The custom attribute prefix "data-" is ignored by the client.


Differences between HTML 4.01 and HTML5

The data-* attribute is new in HTML5.


Syntax

<

element

data-*="

somevalue

">

HTML Global Attributes HTML Global Attributes