Can an HTML element be assigned arbitrary attributes?
For example:
<div imMakingUpAnAttribute="whatever"></div>
Custom attributes are attributes that are not part of the standard HTML5 attributes but are explicitly created. They allow us to add our own information to HTML tags. These are not specific and can be used with all the HTML elements.
Global attributes are attributes common to all HTML elements; they can be used on all elements, though they may have no effect on some elements. Global attributes may be specified on all HTML elements, even those not specified in the standard.
You can have multiple data attributes on an element and be used on any HTML element.
Yes, you can have custom attributes:
<div imMakingUpAnAttribute="whatever"></div>
To differentiate between element and custom attributes, a good practice is to prefix it with data-
.
<div data-imMakingUpAnAttribute="whatever"></div>
Yes, but they must be prefixed with data-
.
A custom data attribute is an attribute in no namespace whose name starts with the string "data-", has at least one character after the hyphen, is XML-compatible, and contains no characters in the range U+0041 to U+005A (LATIN CAPITAL LETTER A to LATIN CAPITAL LETTER Z).
W3C HTML5 Spec: http://dev.w3.org/html5/spec/single-page.html?utm_source=dlvr.it&utm_medium=feed#embedding-custom-non-visible-data-with-the-data-*-attributes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With