- 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 - <tbody> Tag
A separate semantic block is created in an HTML table by the <tbody> tag, which defines the table's body content. The <tbody> tag is used in conjunction with the <thead> and <tfoot> tags, which designate the table's header and footer, respectively. The <tbody> tag must be used as a child of the <table> element, after the <thead>, <caption>, and <colgroup> element. The HTML5 <tfoot> element can be found either before or after the <tbody> element.
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 <tbody> tag −
<tbody>...</tbody>
Example
Following is an example where we are going to use the <tbody> tag in the table.
<!DOCTYPE html> <html> <body> <table border="1"> <thead> <tr> <th>ID</th> <th>NAME</th> </tr> </thead> <tbody> <tr> <td>1567</td> <td>Maya</td> </tr> <tr> <td>1566</td> <td>Ram </td> </tr> <tr> <td>1564</td> <td>Rahul</td> </tr> </tbody> </table> </body> </html>
On running the above code, the output window will pop up, displaying the table on the webpage.
Example
Consider another scenario where we are going to style the <tbody> tag using CSS.
<!DOCTYPE html> <html> <style> th, td { padding: 9px; border: 1.5px solid #DE3163; } </style> <body> <table style="width:50%; border-collapse:collapse;"> <thead> <tr> <th>Items</th> <th>Price</th> </tr> </thead> <tfoot> <tr> <td>Total</td> <td>1100</td> </tr> </tfoot> <tbody style="background-color:#ABEBC6;"> <tr> <td>Chocolates</td> <td>200</td> </tr> <tr> <td>Grocessary</td> <td>900</td> </tr> </tbody> </table> </body> </html>
When we execute the above code, it will generate an output consisting of the table along with CSS applied to the content that comes under the <tbody> tag and is displayed on the webpage.
Example
Let’s look at another example where we are going to align the content inside the <tbody> tag to centre using CSS.
<!DOCTYPE html> <html> <style> table, th, td { border: 1.5px solid #A569BD; } </style> <body> <table style="width:50%"> <thead> <tr> <th>Students</th> <th>Marks</th> </tr> </thead> <tbody style="text-align:center"> <tr> <td>Maya</td> <td>75</td> </tr> <tr> <td>Raj</td> <td>76</td> </tr> <tr> <td>Suresh</td> <td>77</td> </tr> </tbody> </table> </body> </html>
On running the above code, the output window will pop up, displaying the table along with CSS applied to make the content that comes under the <tbody> aligned to centre inside the table.
Example
In the following example, we are going to use the CSS vertical align property to make the content inside the <tbody> tag align to the centre.
<!DOCTYPE html> <html> <style> table, th, td { border: 1.5px solid #2ECC71; } </style> <body> <table style="width:50%;"> <tr> <th>Employee</th> <th>Department</th> </tr> <tbody style="vertical-align:middle"> <tr style="height:100px"> <td>Maya</td> <td>InformationTechnology</td> </tr> <tr style="height:100px"> <td>Ram</td> <td>Analyst</td> </tr> <tr style="height:100px"> <td>Suresh</td> <td>Associate</td> </tr> </tbody> </table> </body> </html>
When we execute the above code, it will generate an output consisting of a table along with a CSS vertical align property for the <tbody> tag.
To Continue Learning Please Login
Login with Google