Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

Element: tagName property

BaselineWidely available

ThetagName read-only propertyof theElement interface returns the tag name of the element on whichit's called.

For example, if the element is an<img>, itstagName property isIMG (for HTML documents; it may be caseddifferently for XML/XHTML documents). Note: You can use thelocalName propertyto access the Element's local name — which for the case in the example isimg (lowercase).

Value

A string indicating the element's tag name. This string's capitalization depends on thedocument type:

  • For DOM trees which represent HTML documents, the returned tag name is always in thecanonical upper-case form. For example,tagName called on a<div> element returns"DIV".
  • The tag names of elements in an XML DOM tree are returned in the same case in whichthey're written in the original XML file. If an XML document includes a tag"<SomeTag>", then thetagName property's value is"SomeTag".

ForElement objects, the value oftagName is the same asthe value of thenodeName property the element objectinherits fromNode.

Examples

HTML

html
<span>When I was born…</span>

JavaScript

js
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 whilecreating the original document.

Specifications

Specification
DOM
# ref-for-dom-element-tagname①

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp