I recently noticed that chrome converts data attributes data-*
to lower case.
e.g.
<div data-Me="awesome"></div>
will be converted to <div data-me="awesome"></div>
in Chrome Dev Tools.
When I call the attribute with javascript:
console.log(e.hasAttribute('data-Me'),e.hasAttribute('data-me'));
both return true.
So whats the standard way to name data attributes?
Since HTML5 isn't case-sensitive, it means that all XHTML tags are the same tag in HTML5. The idea behind HTML5 eschewing case-sensitivity was to make it easier for new web professionals to learn the language.
In HTML, the attribute and tag names are case-insensitive. The close association of HTML and JavaScript can lead to confusion, so case sensitivity is more important in JavaScript.
This statement is False. Explanation : Because, Tags and Attributes are not case sensitive i.e. means if you type the tags in any small or capital alphabets then too it's going to work.
You should always use lowercase characters. Even though some browser do automatically correct mistakes in the markup (that's what Chrome does for you here) it can cause errors and isn't valid HTML5. From MDN:
EDIT
After some more research I've found this:
All attribute names on HTML elements in HTML documents get ASCII-lowercased automatically, so the restriction on ASCII uppercase letters doesn't affect such documents.
HTML5 tags and attributes ARE case INsensitive.
It makes no sense to get information from browser vendors. Instead, you should get that information directly from the source (W3C standards): http://w3c.github.io/html-reference/documents.html#case-insensitivity
You can either use XHTML or HTML5. From a web page loading point of view only HTML5 makes sense currently.
In documents in the HTML syntax: • Tag names for HTML elements may be written with any mix of lowercase and uppercase letters that are a case-insensitive match for the names of the elements given in the HTML elements section of this document; that is, tag names are case-insensitive. • Attribute names for HTML elements may be written with any mix of lowercase and uppercase letters that are a case-insensitive match for the names of the attributes given in the HTML elements section of this document; that is, attribute names are case-insensitive.
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