Introduction to HTML Tables
Tables 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>
HTMLExplanation of Table Elements
<table>
: Defines a table.<tr>
: Represents a row.<th>
: Defines a header cell (bold & centered by default).<td>
: Represents a standard table cell.
Table Styling & Accessibility
Adding Borders and Spacing
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid black;
padding: 10px;
text-align: left;
}
</style>
HTMLAdding Captions for Accessibility
<table>
<caption>Monthly Sales Data</caption>
<tr>
<th>Month</th>
<th>Sales</th>
</tr>
<tr>
<td>January</td>
<td>$5000</td>
</tr>
</table>
HTMLMerging Cells
Colspan (Merge Columns)
<td colspan="2">Merged Columns</td>
HTMLRowspan (Merge Rows)
<td rowspan="2">Merged Rows</td>
HTMLResponsive Tables
<style>
table {
width: 100%;
overflow-x: auto;
display: block;
}
</style>
HTMLHTML tables help display structured data effectively. Next, we’ll cover HTML forms.