HTML tables are used to display data in a structured format using rows and columns. The <table> tag defines the table, <tr> defines a table row, <th> defines a header cell, and <td> defines a standard data cell. Tables can include a caption with the <caption> tag and be styled using CSS for better presentation. Proper use of tables helps in organizing and presenting data clearly.
Examples:
<table>
<caption>Monthly Sales</caption>
<tr>
<th>Month</th>
<th>Sales</th>
</tr>
<tr>
<td>January</td>
<td>$1000</td>
</tr>
<tr>
<td>February</td>
<td>$1200</td>
</tr>
</table>
HTML Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML Tutorial</title>
</head>
<body>
<h1>HTML Tables</h1>
<p>HTML tables are defined with the <code><table></code> tag.</p>
<table>
<caption>Monthly Sales Table</caption>
<tr>
<th>Month</th>
<th>Sales</th>
</tr>
<tr>
<td>January</td>
<td>$1000</td>
</tr>
<tr>
<td>February</td>
<td>$1200</td>
</tr>
</table>
</body>
</html>
The Output of the above code:
HTML Tables
HTML tables are defined with the <table> tag.
| Month | Sales |
|---|---|
| January | $1000 |
| February | $1200 |