

Ask HN: HTML/JS Standards Question - taitems

Nearly everyone (except maybe my coworkers) knows that web standards dictate that lower case HTML tags must always be used. But the question is, why does the JavaScript method .tagName return the object's tag in UPPERCASE?<p>Good Code:<p>&#60;div id="welcome"&#62;Hello&#60;/div&#62;<p>Bad Code:<p>&#60;DIV ID="welcome"&#62;Hello&#60;/DIV&#62;<p>JavaScript:<p>document.getElementById("welcome").tagName;<p>For both, the code would return "DIV" and not "div".
======
jeff18
HTML is not necessarily case sensitive, you can use upper or lowercase tags in
HTML 5, and perhaps others. With that in mind, the tags should be normalized
when querying what an element is (hr == HR == hR == Hr). Uppercase was chosen:

[http://www.whatwg.org/specs/web-apps/current-
work/multipage/...](http://www.whatwg.org/specs/web-apps/current-
work/multipage/apis-in-html-documents.html#apis-in-html-documents)

"These attributes must return element names converted to ASCII uppercase,
regardless of the case with which they were created."

~~~
taitems
While it doesn't break a page visually, uppercase HTML tags restrict a page
from validating properly?

~~~
jeff18
"HTML" in this context is meaningless. Are you talking about XHTML, HTML4,
HTML5 or what? ;)

It depends on the doctype and namespace. In XHTML, an uppercase HR is
technically meaningless, since it is case sensitive. In HTML5, it is not case
sensitive so hR should be valid, according to the spec.

Citation: "In the HTML syntax, tag names, even those for foreign elements, may
be written with any mix of lower- and uppercase letters that, when converted
to all-lowercase, matches the element's tag name; tag names are case-
insensitive."

------
Daniel_Newby
.tagName evaluates to the name of the HTML 4 element, and names are written
all-caps in the HTML 4 and older specifications. All-caps is convenient
because you can write about, for example, the A element by just typing its
name. The standards committees renamed them to lowercase for XHTML and HTML 5,
because writing about 'a' elements is _ever_ so much more consistent. Morons.

P.S. In HTML 4 and older, tags are case insensitive. And practical browsers
will accept both cases for the foreseeable future.

