HTML DOM TableHeader Object

The HTML DOM TableHeader Object represent the <th> element of an HTML document.

Create TableHeader object


Following is the syntax −


Properties of TableHeader object

cellIndexIt returns the position of a cell in the cell collection of a table row.
colSpanIt returns and alter the value of colspan attribute of a table.
headersIt returns and alter the value of headers attribute of a table.
abbrIt returns and alter the value of abbr attribute of a table.
rowSpanIt returns and alter the value of rowspan attribute of a table

Let us see an example of TableHeader object:


 Live Demo

<!DOCTYPE html>
   body {
      color: #000;
      background: lightblue;
      height: 100vh;
      text-align: center;
   table {
      margin: 2rem auto;
      width: 400px;
   .btn {
      background: #db133a;
      border: none;
      height: 2rem;
      border-radius: 2px;
      width: 40%;
      display: block;
      color: #fff;
      outline: none;
      cursor: pointer;
      margin: 1rem auto;
<h1>DOM TableHeader Object Demo</h1>
<table border="2">
<tr class="table-header">
<button onclick="get()" class="btn">Create a TableHeader</button>
   function get() {
      var th1 = document.createElement("TH");
      var th2 = document.createElement("TH");
      th1.innerHTML = "Name";
      th2.innerHTML = "Language";


Click on “Create a TableHeader” button to create a TableHeader object.