Is Element.tagName always uppercase?

You don’t have to toLowerCase or whatever, browsers do behave the same on this point (surprisingly huh?).

About the rationale, once I had discussion with a colleague who’s very professional on W3C standards. One of his opinions is that using uppercase TAGNAME would be much easier to recognize them out of user content. That’s quite persuasive for me.


Edit: As @adjenks says, XHTML doctype returns mixed-case tagName if the document is served as Content-Type: application/xhtml+xml. Test page: http://programming.enthuses.me/tag-node-case.php?doc=x

Technically, please read this spec for more info: http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-745549614

Note that this (tagName) is case-preserving in XML, as are all of the operations of the DOM. The HTML DOM returns the tagName of an HTML element in the canonical uppercase form, regardless of the case in the source HTML document.

As of asker’s question: this is trustable. Breaking change is not likely to happen in HTML spec.

Leave a Comment