- 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 - <tr> Tag
In an HTML table, a row is defined with the <tr> tag. Each <tr> tag can have one or more <th> tag that specify the table's header cells or one or more <td> tag that define the table's standard cells. The <tr> tag can either be a nested child of the <thead>, <tbody>, and <tfoot> elements or a direct child of the <table> element.
Syntax
Following is the syntax for HTML <tr> −
<tr> ...... </tr>
Example
Let's consider the following example, where we are going to use the <tr> tag.
<!DOCTYPE html> <html> <style> table, th, td { border: 1.25px solid #DE3163; } </style> <body> <table> <tr> <th>University</th> <th>Place</th> </tr> <tr> <td>LPU</td> <td>Punjab</td> </tr> <tr> <td>Amity</td> <td>Noida</td> </tr> <tr> <td>Amrutha</td> <td>Coimbatore</td> </tr> </table> </body> </html>
On running the above code, the output window will pop up, displaying the table on the webpage.
Example
Considering another scenario where we are going to apply th background-color to the <tr> tag.
<!DOCTYPE html> <html> <style> table, th, td { border: 1px solid black; } </style> <body> <table> <tr> <th>Bike</th> <th>Owner</th> </tr> <tr style="background-color:#D5F5E3;"> <td>RX100</td> <td>Ravi</td> </tr> <tr style="background-color:#D2B4DE ;"> <td>Continental</td> <td>Arjun</td> </tr> </table> </body> </html>
When we execute the above code, it will generate an output consisting of the table along with a background color added to the data that comes under the <tr> tag displayed on the webpage.
Example
In the following example, we are going to align the <tr> tag to the center using the CSS.
<!DOCTYPE html> <html> <style> table, th, td { border: 1.5px solid #A569BD; } </style> <body> <table style="width:100%"> <tr> <th>Country</th> <th>Capital</th> </tr> <tr style="text-align:center"> <td>Afghanistan</td> <td>Kabul</td> </tr> <tr style="text-align:center"> <td>Albania</td> <td>Tirane</td> </tr> </table> </body> </html>
On running the above code, the output window will pop up, displaying the data that comes under the <tr> tag displayed at the center inside the table.
Example
Following is an example where we are going to use the rowspan and colspan.
<!DOCTYPE html> <html> <style> th, td { border: 1.5px solid #A569BD; } table { border-collapse: collapse; } </style> <body> <table> <tr> <th rowspan=2>Name</th> <th colspan=2>Contact Details</th> </tr> <tr> <th>Mobile</th> <th>Landline</th> </tr> <tr> <td>Suresh</td> <td>0987654321</td> <td>123456</td> </tr> <tr> <td>Ramesh</td> <td>1256789543</td> <td>234562</td> </tr> <tr> <td>Kamal</td> <td>88976765432</td> <td>009875242</td> </tr> </table> </body> </html>
When we execute the above code, it will generate an output consisting of the table mentioned with a rowspan and colspan displayed on the webpage.