tagName (W3C DOM Core property)

Version Depr. Static Read-only
DOM1 No No Yes
Browser support (more…)
IE5.5+ FF1.5+ SA1.3+ OP9+
Full Full Full Full


var tag = element.tagName;

The example above saves a reference to the tagName of an element, so if the element reference pointed to an HTML blockquote element:

  <p>I found some kinda fairytale</p>

Then the tag variable would have the value BLOCKQUOTE.


The qualified name of an Element node, including any namespace prefix.

In HTML this is returned in all uppercase regardless of the case used in the document; in XML the case used in the document is preserved.

In all cases, the tagName of an element is exactly the same as its nodeName.

This property is readonly.

Tip: Getting consistent results

Since the case of the returned value depends on whether the document is HTML or XML (which includes XHTML mode1), it's often helpful to run this value through JavaScript's toLowerCase function, to get a value with predictable case:

var tag = element.tagName.toLowerCase();

The tag variable would then have the value blockquote, regardless of the document type.


Internet Explorer Firefox Safari Opera
5.5 6.0 7.0 1.5 2.0 3.0 1.3 2.0 3.0 9.0 9.5
Full Full Full Full Full Full Full Full Full Full Full
: Behavior in HTML

Opera in HTML mode2 returns the tagName of a namespaced element in its specified case, rather than uppercase; however since HTML mode documents are not supposed to contain namespaced elements, this cannot be considered a bug.


1 On XHTML pages served as application/xhtml+xml.

2 On XHTML or HTML pages served as text/html.

User-contributed notes

There are no comments yet.

Related Products