- HTML Tutorial
- HTML - Home
- HTML - History and Evolution
- HTML - Overview
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Headings
- HTML - Paragraphs
- HTML - Quotations
- HTML - Comments
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Style Sheet
- HTML - CSS Classes
- HTML - CSS IDs
- HTML - Images
- HTML - Image Map
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Iframes
- HTML - Blocks
- HTML Backgrounds
- HTML - Backgrounds
- HTML Colors
- HTML - Colors
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Code Builder
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - <thead> Tag
In an HTML table, header content is grouped using the <thead> tag. The <thead> element is used in conjunction with the <tbody> and <tfoot> elements to provide the header, body, and footer of a table. By default, the <thead>, <tbody>, and <tfoot> elements have no impact on how the table is organised. However, you can style these elements with CSS.
These elements can be used by browsers to enable table body scrolling separate from header and footer scrolling. These features can also make it possible for the table header and footer to be printed at the top and bottom of each page when publishing a large table that spans multiple pages.
Syntax
Following is the syntax for HTML <thead> tag −
<thead>...</thead>
Example
Let’s look at the following example, where we are going to use the <thead> tag.
<!DOCTYPE html> <html> <style> table, th, td { border: 1.5px solid #DE3163; } </style> <body> <table> <thead> <tr> <th>Subjects</th> <th>Marks</th> </tr> </thead> <tbody> <tr> <td>1A</td> <td>72</td> </tr> <tr> <td>1B</td> <td>74</td> </tr> <tr> <td>2B</td> <td>73</td> </tr> </tbody> <tfoot> <tr> <td>Total</td> <td>219</td> </tr> </tfoot> </table> </body> </html>
On running the above code, the output window will pop up, consisting of the table displayed on the webpage.
Example
Considering another scenario where we are going to style the <thead>, <tbody>, and <tfoot> using CSS.
<!DOCTYPE html> <html> <style> thead { color: #6C3483; } tbody { color: #196F3D; } tfoot { color: #DE3163; } table, th, td { border: 1.5px solid #5DADE2; } </style> <body> <table> <thead> <tr> <th>Items</th> <th>Price</th> </tr> </thead> <tbody> <tr> <td>5Star</td> <td>$20</td> </tr> <tr> <td>KitKat</td> <td>$25</td> </tr> <tr> <td>MilkyBar</td> <td>$10</td> </tr> </tbody> <tfoot> <tr> <td>Total Bill</td> <td>$55</td> </tr> </tfoot> </table> </body> </html>
When we execute the above code, it will generate an output consisting of the table with CSS applied to the <thead>, <tbody>, and <tfoot> displayed on the webpage.
Example
Following is an example where we are going to align the content inside the <thead> tag to the right using CSS.
<!DOCTYPE html> <html> <style> table, th, td { border: 1.5px solid #DE3163; } </style> <body> <table style="width:100%"> <thead style="text-align:right"> <tr> <th>Employees</th> <th>Age</th> </tr> </thead> <tbody> <tr> <td>Ram</td> <td>23</td> </tr> <tr> <td>Raju</td> <td>22</td> </tr> <tr> <td>Maya</td> <td>24</td> </tr> </tbody> </table> </body> </html>
On running the above code, the output window will pop up, displaying the table on the webpage along with the content inside the <thead> tag displayed to the right.
Example
In the following example, we are going to use the CSS vertical align property to align the content inside the <thead> tag.
<!DOCTYPE html> <html> <style> table, th, td { border: 1.5px solid #A569BD; } </style> <body> <table style="width:50%"> <thead style="vertical-align:middle"> <tr style="height:50px"> <th>Cars</th> <th>Countries</th> </tr> </thead> <tbody> <tr> <td>Maserati</td> <td>Italy</td> </tr> <tr> <td>Porsche</td> <td>Germany</td> </tr> <tr> <td>Dodge</td> <td>US</td> </tr> </tbody> </table> </body> </html>
When we execute the above code, it will generate an output consisting of the table displayed on the webpage along with content inside the <thead> tag that is aligned to the middle using the CSS vertical align property.