Table Basics
Part of the Fundamentals section of Coddy's HTML journey — lesson 48 of 60.
In HTML, a table is a way to organize data into rows and columns. Tables are commonly used to display data in a structured format, such as schedules, statistics, or any other type of information that can be presented in a grid. To create a table, you use the <table> tag along with other tags like <tr> for table rows, <td> for table data (cells), and <th> for table headers.
Here's the basic structure of an HTML table:
<table>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
</tr>
<tr>
<td>Row 2, Cell 1</td>
<td>Row 2, Cell 2</td>
</tr>
</table><table>: The tag that defines the table.
<tr>: The tag that defines a table row.
<th>: The tag that defines a header cell. Header cells are typically used for column or row titles and are displayed in bold by default.
<td>: The tag that defines a standard cell in the table.
Here's how this table would be rendered in a browser:
| Header 1 | Header 2 |
|---|---|
| Row 1, Cell 1 | Row 1, Cell 2 |
| Row 2, Cell 1 | Row 2, Cell 2 |
In this example, we have a table with two rows and two columns. The first row contains header cells, and the subsequent rows contain regular data cells. This structure creates a simple grid layout that is easy to read and understand.
Challenge
EasyCreate an HTML document that includes a table with the following structure:
- A
<table>tag to define the table. - A table row (
<tr>) for the header with two header cells (<th>). The first header cell should say "Name", and the second should say "Age". - A table row (
<tr>) with two data cells (<td>). The first cell should say "John", and the second should say "30". - Another table row (
<tr>) with two data cells (<td>). The first cell should say "Jane", and the second should say "25".
Cheat sheet
HTML tables organize data into rows and columns using the <table> tag:
<table>: Defines the table<tr>: Defines a table row<th>: Defines a header cell (displayed in bold by default)<td>: Defines a standard data cell
<table>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
</tr>
<tr>
<td>Row 2, Cell 1</td>
<td>Row 2, Cell 2</td>
</tr>
</table>Try it yourself
<!DOCTYPE html>
<html>
<body>
<!-- Write code here -->
</body>
</html>This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
2Text and Formatting
HeadingsParagraphsLine BreaksBold and Italic TextBold and Italic AgainRecap - Formatting8Forms and Inputs Part 1
Form BasicsText InputsInput AttributesPassword FieldLabels for InputsRecap - Basic Form11Event Registration Page
Project OverviewHeader Section9Forms and Inputs Part 2
Radio ButtonsCheckboxesDropdownsButtonsButtons in FormsRecap - Forms #1Recap - Forms #2