Introduction to HTML Tables
HTML tables are used to display data in a tabular format. A table consists of rows, and each row contains cells that can hold data or header information.
The basic structure of a table includes the following tags:
<table>
: Defines the table.<tr>
: Defines a table row.<th>
: Defines a header cell.<td>
: Defines a data cell.
Creating a Simple Table
Example: A basic table with three columns and two rows.
<table border="1">
<tr>
<th>Name</th>
<th>Age</th>
<th>City</th>
</tr>
<tr>
<td>Alice</td>
<td>24</td>
<td>New York</td>
</tr>
<tr>
<td>Bob</td>
<td>30</td>
<td>Los Angeles</td>
</tr>
</table>
Try It Yourself
Quiz: Test Your Knowledge
Which HTML element is used to define a table row?
Coding Challenge
Create a table that displays the following information:
- Three columns: Item, Quantity, Price
- Four rows of data representing different items and their quantities and prices.