Computer >> Computer tutorials >  >> Programming >> Javascript

Creating custom attributes with HTML5


A new feature introduced in HTML 5 is the addition of custom data attributes.

A custom data attribute starts with data- and would be named based on your requirement.

<div class = "example" data-sports = "cricket" data-level = "complex">
   ...
</div>

The above will be perfectly valid HTML5 with two custom attributes called data-subject and data-level. You would be able to get the values of these attributes using JavaScript APIs or CSS in a similar way as you get for standard attributes.