HTML / HTML Tables
Creating a Basic HTML Table
This tutorial covers the basics of creating a table in HTML. You'll learn how to use the <table>, <tr>, and <td> tags to create a simple table.
Section overview
5 resourcesCovers the creation and styling of tables in HTML.
1. Introduction
In this tutorial, we will be learning about how to create a basic HTML table. The goal is to understand how HTML tables work and how we can create them.
By the end of this tutorial, you will learn:
- The significance and usage of the <table>, <tr>, and <td> HTML tags
- How to create a simple HTML table
Prerequisites for this tutorial include:
- Basic understanding of HTML
- Familiarity with HTML tags
2. Step-by-Step Guide
HTML tables are created using a combination of the following tags:
- <table>: This is the container tag used to define a table
- <tr>: This tag stands for table row and is used to define a row in the table
- <td>: This tag stands for table data and is used to define a cell in the table
Here's a simple example of how these tags are used to create a table:
<table>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
</tr>
<tr>
<td>Cell 3</td>
<td>Cell 4</td>
</tr>
</table>
This code will create a table with 2 rows and 2 columns.
Best practices and tips:
- Always close your HTML tags to prevent unexpected results
- Use indentation to make your code easier to read and understand
3. Code Examples
Example 1:
Let's create a simple table with 2 rows and 2 columns:
<table>
<!-- Row 1 -->
<tr>
<td>Row 1, Column 1</td>
<td>Row 1, Column 2</td>
</tr>
<!-- Row 2 -->
<tr>
<td>Row 2, Column 1</td>
<td>Row 2, Column 2</td>
</tr>
</table>
In this example, we have 2 <tr> tags, each representing a row, and each row has 2 <td> tags, each representing a cell in that row.
The output will be a simple table with 2 rows and 2 columns.
Example 2:
<table>
<!-- Headers -->
<tr>
<th>Name</th>
<th>Age</th>
<th>Location</th>
</tr>
<!-- Row 1 -->
<tr>
<td>John Doe</td>
<td>27</td>
<td>New York</td>
</tr>
<!-- Row 2 -->
<tr>
<td>Jane Doe</td>
<td>25</td>
<td>Los Angeles</td>
</tr>
</table>
In this example, we use the <th> tag, which stands for table header, to create a header row for our table.
4. Summary
In this tutorial, we've learned:
- The purpose and usage of the <table>, <tr>, and <td> HTML tags
- How to create a simple HTML table
To continue learning, you can explore more complex table structures and additional table-related tags, such as <thead>, <tbody>, and <tfoot>.
5. Practice Exercises
Practice makes perfect. Try out these exercises to reinforce what you've learned:
1. Create a table with 3 rows and 3 columns
2. Create a table with headers and at least 2 rows of data
3. Create a table with nested tables (a table inside a table)
Remember to always close your tags and use indentation for better readability.
Keep practicing and exploring. Happy coding!
Need Help Implementing This?
We build custom systems, plugins, and scalable infrastructure.
Related topics
Keep learning with adjacent tracks.
Popular tools
Helpful utilities for quick tasks.
Latest articles
Fresh insights from the CodiWiki team.
AI in Drug Discovery: Accelerating Medical Breakthroughs
In the rapidly evolving landscape of healthcare and pharmaceuticals, Artificial Intelligence (AI) in drug dis…
Read articleAI in Retail: Personalized Shopping and Inventory Management
In the rapidly evolving retail landscape, the integration of Artificial Intelligence (AI) is revolutionizing …
Read articleAI in Public Safety: Predictive Policing and Crime Prevention
In the realm of public safety, the integration of Artificial Intelligence (AI) stands as a beacon of innovati…
Read articleAI in Mental Health: Assisting with Therapy and Diagnostics
In the realm of mental health, the integration of Artificial Intelligence (AI) stands as a beacon of hope and…
Read articleAI in Legal Compliance: Ensuring Regulatory Adherence
In an era where technology continually reshapes the boundaries of industries, Artificial Intelligence (AI) in…
Read article