HTML DOM Element tagName attribute

Definition and usage

tagName The attribute returns the tag name of the element.

In HTML,tagName The return value of the attribute is always in uppercase.

tagName Attributes are read-only.

See also:

nodeName property

nodeType property

nodeValue property

The difference between tagName and nodeName

nodeName Attributes can also return the tag name of the element.

nodeName It can also return the names of attribute nodes, text nodes, and comment nodes.

Instance

Example 1

Get the tagName of the "demo" element:

let name = document.getElementById("demo").tagName;

Try it yourself

Example 2

Find out which element triggered the event:

const element = event.target;
let name = element.tagName;

Try it yourself

Syntax

element.tagName

Return value

Type Description
String The tag name of the element.

Browser support

element.tagName It is a feature of DOM Level 1 (1998).

All browsers fully support it:

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Support 9-11 Support Support Support Support