Tables
Exercise
- In the "index.html" file, write the following code:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>My First Web Page</title> </head> <body> </body> </html>
- Save.
- If "Live Server" is not already running, right-click anywhere in the editor and select "Open with Live Server" from the context menu.
- Add the following between the opening and closing tags of the body:
<h1>Pizza</h1> <h3>Table of Pizza Prices</h3> <table> <tr> <th>Toppings</th> <th>Price</th> </tr> <tr> <td>Cheese</td> <td>10.00</td> </tr> <tr> <td>Mushrooms</td> <td>11.00</td> </tr> <tr> <td>Pepperoni</td> <td>12.00</td> </tr> </table>
- Save.
- In the browser, you should see the following:
Code Walkthrough and Explanation
<table></table>
The <table>
tag in HTML is used to create a table. A table is a data structure that
organizes
information into rows and columns. Tables are commonly used to display data in a structured manner, such as for
displaying information about products in an e-commerce website or for displaying results from a database query.
<tr></tr>
The <tr>
tag represents a table row.
<th></th>
The <th>
tag represents a table header cell, which is typically used to provide a label for
the
columns in a table.
<td></td>
The <td>
tag represents a table cell.
Experiment with the Code
- Try adding more rows to the table.
- Try adding more columns to the table.
- Try adding another table.
Video and Code
Questions? Subscribe and ask in the video comments: