/

HTML / CSS / JavaScript Tutorial

HTML Element: <thead>

[this page | pdf | back links]

The HTML <thead> element indicates the header content of a table. It appears inside a <table> element and is used in conjunction with <tbody> and <tfoot> elements to differentiate between different parts of the table. This can allow browsers to scroll the table body independently of the header and footer, or to allow printing of the header and footer at the top and bottom of each page. A <thead> element needs to come after any <caption> and <colgroup> elements and before any <tbody>, <tfoot> and <tr> elements.

 

The attributes it can take are HTML global attributes and HTML event attributes.

 

It used to support the align, char, charoff and valign attributes, but these are no longer supported by HTML 5.

 

To create or access such an element in JavaScript see here. The corresponding HTML DOM object supports standard DOM properties and methods. The default style applicable to this element is shown here.

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
table,td,th,tr,caption {border: thin solid black; border-collapse: collapse;}
th {background-color: yellow;}
thead {color: blue}
tbody {color: black}
tfoot {color: green}
</style>
</head>
<body>
Created using HTML:<br>
<table>
  <thead>
    <tr><th>col1</th><th>col2</th></tr>
    <tr><td>1</td><td>2</td></tr>
  </thead>
</table>

<br>Created using JavaScript:<br>
<span id="element"></span>

<script>
var y2a1 = document.createElement("TH"); y2a1.textContent = "col1";
var y2a2 = document.createElement("TH"); y2a2.textContent = "col2";
var y2a = document.createElement("TR"); y2a.appendChild(y2a1); y2a.appendChild(y2a2);
var y2b1 = document.createElement("TD"); y2b1.textContent = "1";
var y2b2 = document.createElement("TD"); y2b2.textContent = "2";
var y2b = document.createElement("TR"); y2b.appendChild(y2b1); y2b.appendChild(y2b2);
var y2 = document.createElement("THEAD"); y2.appendChild(y2a); y2.appendChild(y2b);
var x = document.createElement("TABLE");
x.appendChild(y2);
document.getElementById("element").appendChild(x);
</script>

</body>
</html>


NAVIGATION LINKS
Contents | Prev | Next | HTML Elements


Desktop view | Switch to Mobile