HTML DOM tagName Property

The HTML DOM tagname property returns the tag name of the HTML element in an HTML document.


Following is the syntax −


Let us see an example of HTML DOM tagName property−


 Live Demo

<!DOCTYPE html>
   body {
      color: #000;
      height: 100vh;
      background-color: #FBAB7E;
      background-image: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%);
      text-align: center;
   .btn {
      background: #db133a;
      border: none;
      height: 2rem;
      border-radius: 2px;
      width: 40%;
      display: block;
      color: #fff;
      outline: none;
      cursor: pointer;
      margin: 1rem auto;
<h1>HTML DOM tagName Property Demo</h1>
<button class="btn" onclick="display()">Click me to show my tag name</button>
<div class="show"></div>
   function display() {
      document.querySelector('.show').innerHTML = 'Tag name is: ' +                document.querySelector('button').tagName;


Click on “Click me to show my tag name” button to display the tag name of the red button.