- 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 - <table> Tag
The HTML table offers a mechanism to define or derive data in terms of rows and columns of cells, including text, photos, links, and other types of data. The <table> tag can be used to build HTML tables. The table data is left aligned by default.
One <table> element, along with one or more <tr>, <th>, and <td> elements, make up an HTML table. A table row is defined by the <tr >element, a table header is defined by the <th> element, and a table cell is defined by the <td> element. To control the page's layout, such as the header section, navigation bar, body text, and footer section, HTML tables are employed
Syntax
Following is the syntax for HTML <table> −
<table> ....... </table>
Example
Let's consider the following example, where we are going to construct a simple table.
<!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>
On running the above code, the output window will pop up, displaying the table applied with CSS on the webpage.
Example
Considering the another scenario, where we are going to add padding to the table
<!DOCTYPE html> <html> <style> table, th, td { border: 2px solid #82E0AA; } th, td { padding: 11px; } </style> <body> <table> <tr> <th>Cars</th> <th>Owners</th> </tr> <tr> <td>BMW</td> <td>Raju</td> </tr> <tr> <td>RS7</td> <td>Ravi</td> </tr> <tr> <td>Audi</td> <td>Maya</td> </tr> </table> </body> </html>
When we execute the above code, it will generate an output consisting of the table applied with CSS and the padding provided displayed on the webpage.
Example
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>
On running the above code, the output window will pop up, displaying the text along with a table that is assigned to the right of the webpage.
Example
Following is an example where we are going to add background colour to the table.
<!DOCTYPE html> <html> <style> table, th, td { border: 1px solid #6C3483; } </style> <body> <table style="background-color:#ABEBC6 "> <tr> <th>Owner</th> <th>Pet</th> </tr> <tr> <td>Maya</td> <td>Cat</td> </tr> <tr> <td>Raju</td> <td>Dog</td> </tr> <tr> <td>Ravi</td> <td>Pomeranian</td> </tr> </table> </body> </html>
When we execute the above code, it will generate an output consisting of a table applied with a background color displayed on the webpage.
To Continue Learning Please Login
Login with Google