Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 728
Tachi Avatar asked May 23 '15 21:05

Tachi


People also ask

What are data attributes?

In short, a data attribute is a single-value descriptor for a data point or data object. It exists most often as a column in a data table, but can also refer to special formatting or functionality for objects in programming languages such as Python.


1 Answers

data-* attributes are custom HTML attributes.

Basically, there are 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 owner's application. They can be used to simplify an application's 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 but then the HTML standard adds a sound attribute meaning something other than what you meant. Had you used data-sound, you would have been fine because there would be no conflict. The specification says no future standard browser attributes will start with data-.

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.

like image 175
AmmarCSE Avatar answered Oct 02 '22 22:10

AmmarCSE