HTML tables are used to organize and display data in a tabular format on web pages. They are created using a combination of HTML tags to define the structure and content of the table. Here’s a brief overview of the main elements used to create HTML tables:
<table>: This tag defines the beginning and end of the table.
<tr>: This tag defines a table row.
<th>: This tag defines a table header cell, which is typically bold and centered.
<td>: This tag defines a table data cell.
Here is a simple example of an HTML table:
<table border="1">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
</tr>
<tr>
<td>John</td>
<td>Taylor</td>
<td>35</td>
</tr>
<tr>
<td>Tom</td>
<td>Taylor</td>
<td>30</td>
</tr>
</table>
In this example:
The <table border=”1″>element creates a table with a border.
The <tr> elements define rows in the table.
The first row uses <th> elements for headers: “First Name,” “Last Name,” and “Age.”
Subsequent rows use <td> elements for data cells, such as “John,” “Taylor,” and “35.”
HTML Tables – Questions and Answers
Q 1: Which tag is used to create a table?
Ans: <table> tag.
Q 2: Which tag defines table rows?
Ans: <tr>.
Q 3: Difference between <th> and <td>?
Ans: <th> is for headers, <td> is for data.
Q 4: Which tag groups table header content?
Ans: <thead>.
Q 5: How do you add table borders?
Ans: Using CSS border property.
HTML Tables – Objective Questions (MCQs)
Q1. Which tag defines a table in HTML?
Q2. Which tag defines a table row?
Q3. Which tag defines a table header cell?
Q4. Which tag defines a table data cell?
Q5. Which tag groups table header content separately from table body?