docs.rodeo

MDN Web Docs mirror

Element: tagName property

{{ApiRef("DOM")}} 

The tagName read-only property of the {{domxref("Element")}}  interface returns the tag name of the element on which it’s called.

For example, if the element is an {{HTMLElement("img")}} , its tagName property is IMG (for HTML documents; it may be cased differently for XML/XHTML documents). Note: You can use the {{domxref("Element.localName", "localName")}}  property to access the Element’s local name — which for the case in the example is img (lowercase).

Value

A string indicating the element’s tag name. This string’s capitalization depends on the document type:

For {{domxref("Element")}}  objects, the value of tagName is the same as the value of the {{domxref("Node.nodeName", "nodeName")}}  property the element object inherits from {{domxref("Node")}} .

Examples

HTML

<span id="born">When I was born…</span>

JavaScript

const span = document.getElementById("born");
console.log(span.tagName);

In XHTML (or any other XML format), the original case will be maintained, so "span" would be output in case the original tag name was created lowercase. In HTML, "SPAN" would be output instead regardless of the case used while creating the original document.

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN