what are data-* HTML attributes?

I've recently found on one of the sites opening tag like this:

<script data-ip="93.1xx.3.2x" data-backuri="something.com">

And I couldn't find any information about it. What are those tags used for?



data-* attributes are custom HTML attributes.

Basically, there is standard HTML attributes like style, src, width, height, class... and these have a special meaning to browsers and are 'reserved'.

However, custom attributes have no special meaning generally and are only special to the owners application. They can be used to simplify an applications logic.

Using data- before your attribute name ensures that future standard attributes will not use your current attribute. For example, imagine today you are using a sound attribute. Had you used data-sound, you would be fine because specification says it will not be used by future browsers. Rather, no future standard browser attributes will contain data- before them.

See jquery get HTML 5 Data Attributes with hyphens and Case Sensitivity for some useful info on why we use data-* attributes.

Also, see MDN docs for some useful information.


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.