Tables in HTML
? Tables in HTML
Tables in HTML are used to organize and display data in rows and columns.
? Basic Table Structure
<table> <tr> <th>Header 1</th> <th>Header 2</th> </tr> <tr> <td>Data 1</td> <td>Data 2</td> </tr></table>? Tags Used:
| Tag | Description |
|---|---|
<table> | Creates the table |
<tr> | Table row |
<th> | Table header cell (bold, centered) |
<td> | Table data cell |
? Add Border and Styling
<table border="1"> <tr> <th>Name</th> <th>Age</th> </tr> <tr> <td>Alice</td> <td>25</td> </tr></table>Or with CSS:
<style> table { border-collapse: collapse; width: 50%; } th, td { border: 1px solid #999; padding: 8px; text-align: left; } th { background-color: #f2f2f2; }</style>? Advanced Features
Merging Cells:
colspan– merge columnsrowspan– merge rows
<td colspan="2">Merged Column</td><td rowspan="2">Merged Row</td>? Table Example
<table> <tr> <th>Product</th> <th>Price</th> <th>Available</th> </tr> <tr> <td>Laptop</td> <td>$999</td> <td>??</td> </tr> <tr> <td>Phone</td> <td>$499</td> <td>?</td> </tr></table>? Tips
Always use
<thead>,<tbody>, and<tfoot>for large tables.Use CSS for better appearance and responsiveness.
Would you like a responsive table example or a downloadable HTML table template?