- 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
HTML <thead> tag is used to group the header content of HTML table. It is used in conjunction with <tbody> and <tfoot> elements to specify each part of a table.
The <thead> tag ahould be used as a child of a <table> element, preceding any <tbody>, <tfoot>, and <tr> elements, and following any <caption> and <colgroup> elements. Browsers can use these elements to enable scrolling of the table body independently of the header and footer.
Syntax
<thead> ... </thead>
Attribute
HTML tfoot tag supports Global and Event attributes of HTML. Bellow mentioned attributes are deprecated so use CSS properties rather using these attributes.
Attribute | Value | Description |
---|---|---|
align | left right center justify |
Specifies the alignment of text content(Deprecated). |
bgcolor | color | Specifies the background color of each column cell(Deprecated). |
char | character | Specifies the alignment of the content to a character of each column cell(Deprecated). |
charoff | number | Specifies the number of characters to offset the column cell content from the alignment character specified by the char attribute(Deprecated). |
valign | baseline bottom middle top |
Specifies the vertical alignment of each column cell(Deprecated). |
Examples of HTML thead Tag
Bellow examples will illustrate the usage of thead tag. Where, when and how to use thead tag to create header in HTML.
Creating Header in Table
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>
Styling Table
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>
Align Header Content
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>
Vertical Alignment of Header Content
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>
Supported Browsers
Tag | |||||
---|---|---|---|---|---|
thead | Yes | Yes | Yes | Yes | Yes |
To Continue Learning Please Login
Login with Google