
- HTML Home
- HTML Roadmap
- HTML Introduction
- HTML History & Evolution
- 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 - Frames
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Code Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Table Headers & Captions
- 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 & RGBA Colors
- HTML - HEX Colors
- HTML - HSL & HSLA Colors
- HTML - HSL Color Picker
- 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 - Document Object Model (DOM)
- 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 - Character 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 - <table> Tag
Introduction to <table> Tag
The HTML <table> tag is used to create and structure the tabular data. It organizes the information in rows and columns, making it visually clear and easily accessible.
Tables are useful for displaying the data such as schedules, pricing plans or any dataset requiring a grid layout. The basic structure of the table includes rows(<tr>), headers(<th>) and data cells (<td>).
Syntax
Following is the syntax of HTML <table> tag −
<table> ..... </table>
Attribute
HTML table 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). |
border | pixels | Specifies the the border surrounding the table.(Deprecated). |
cellpadding | pixels | space between the content of a cell and its border(Deprecated). |
cellspacing | pixels | Specifies the size of the space between two cells.(Deprecated). |
frame | void above below hsides vsides lhs rhs box border |
Specifies the side of the frame surrounding the table must be displayed(Deprecated). |
rules | none groups cols all |
Defines where rules (borders) are displayed in the table(Deprecated). |
summary | text | Specifies an alternative text that summarizes the content of the table(Deprecated). |
width | pixels | Specifies width of the table(Deprecated). |
Example : Basic Table
Let's look at the following example, where we are going to create the basic table using the <table> tag.
<!DOCTYPE html> <html> <style> table, th, td { border: 2px solid #6C3483; } </style> <body> <table> <tr> <th>Employee</th> <th>Salary</th> </tr> <tr> <td>Maya</td> <td>32k</td> </tr> <tr> <td>Raju</td> <td>25k</td> </tr> <tr> <td>Rahul</td> <td>20k</td> </tr> </table> </body> </html>
Example : Table with Caption
Consider the following example, where we are going to use the <caption> tag along with the <table> tag.
<!DOCTYPE html> <html> <body> <table border="1"> <caption>Student Grades</caption> <tr> <th>Name</th> <th>Grade</th> </tr> <tr> <td>Ramesh</td> <td>A</td> </tr> <tr> <td>Suresh</td> <td>B</td> </tr> </table> </body> </html>
Example : Table Alignment
In the following example, we are going to use the CSS property to make the table align to the right.
<!DOCTYPE html> <html> <style> table, th, td { border: 2px solid #ABEBC6; } </style> <body> <table style="float:right"> <tr> <th>Team</th> <th>Points</th> </tr> <tr> <td>CSK</td> <td>16</td> </tr> <tr> <td>MI</td> <td>14</td> </tr> <tr> <td>RR</td> <td>14</td> </tr> <tr> <td>KKR</td> <td>12</td> </tr> </table> <p><br><br> The Indian Premier League is a men's Twenty20 cricket league that is annually held in India and contested by ten city-based franchise teams. The BCCI founded the league in 2007. </p> </body> </html>
Example : Merging Cells
Following is teh example, where we are going to use the colspan along with the <table> tag.
<!DOCTYPE html> <html> <body> <table border="1"> <tr> <th>Name</th> <th colspan="2">Runs</th> </tr> <tr> <td>Suresh</td> <td>35</td> <td>50</td> </tr> </table> </body> </html>
Supported Browsers
Tag | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
table | Yes | Yes | Yes | Yes | Yes |