HTML table
Created By: chatGPT
An HTML table is used to display data in a structured format with rows and columns. The
<table>
element is used to create the table, and it can be enhanced with headings, borders, and other formatting options.<table>
<thead>
<tr>
<th>Header 1</th>
<th>Header 2</th>
<th>Header 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
<td>Row 1, Cell 3</td>
</tr>
<tr>
<td>Row 2, Cell 1</td>
<td>Row 2, Cell 2</td>
<td>Row 2, Cell 3</td>
</tr>
<tr>
<td>Row 3, Cell 1</td>
<td>Row 3, Cell 2</td>
<td>Row 3, Cell 3</td>
</tr>
</tbody>
</table>
To style your table, you can use CSS. For example, you might want to add borders, padding, or change the background color to make it more appealing.
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
</style>
Inserting a caption in an HTML table can provide a brief description of its content. The
<caption>
tag is placed immediately after the <table>
tag.<table>
<caption>Sample Table Caption</caption>
<thead>
<tr>
<th>Header 1</th>
<th>Header 2</th>
<th>Header 3</th>
</tr>
</thead>
<tbody>
<!-- Table rows go here -->
</tbody>
</table>
You can also use rowspan and colspan attributes within the
<td>
tag to merge rows and columns respectively. This can help create more complex layouts.<table>
<thead>
<tr>
<th colspan="2">Merged Header</th>
<th>Header 3</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2">Row 1-2</td>
<td>Row 1, Cell 2</td>
<td>Row 1, Cell 3</td>
</tr>
<tr>
<td>Row 2, Cell 2</td>
<td>Row 2, Cell 3</td>
</tr>
</tbody>
</table>