Creating custom attributes with HTML5

JavascriptWeb DevelopmentFront End Scripts

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">

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.

Published on 11-Apr-2018 14:49:06