- HTML Tutorial
- HTML - Home
- HTML - Introduction
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Headings
- HTML - Paragraphs
- HTML - Fonts
- HTML - Blocks
- HTML - Style Sheet
- HTML - Formatting
- HTML - Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- 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 Color Names & Values
- HTML - Color Names
- 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 Picker
- HTML References
- HTML - Cheat Sheet
- 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. The row's cells can then be established using a mix of <td> and <th> elements.
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
<tr> .... </tr>
Attribute
HTML tr 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 tr Tag
Bellow examples will illustrate the usage of tr tag. Where, when and how to use tr tag to create table row.
Creating Simple HTML Table
Let's consider the following example, where we are going to use the <tr> tag to create three rows, one header row and two data rows.
<!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>
Adding Background Color on Table Row
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>
Align Table row Content
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>
Spanning Multiple Rows and Columns
Following is an example where we are going to use the rowspan and colspan on the tr tag to manipulate the area of table row.
<!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>
Supported Browsers
Tag | |||||
---|---|---|---|---|---|
tr | Yes | Yes | Yes | Yes | Yes |