-
Hajipur, Bihar, 844101
An HTML table allows you to arrange data in rows and columns, just like in Excel. Tables are useful for displaying structured information such as price lists, schedules, or statistics.
<table>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
</table>
Tag | Description |
---|---|
<table> |
Defines the table |
<tr> |
Table row |
<th> |
Table header cell (bold & centered) |
<td> |
Table data cell |
<table border="1">
<tr>
<th>Roll No</th>
<th>Name</th>
<th>Marks</th>
</tr>
<tr>
<td>1</td>
<td>Alice</td>
<td>95</td>
</tr>
<tr>
<td>2</td>
<td>Bob</td>
<td>89</td>
</tr>
</table>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid #444;
padding: 8px;
text-align: center;
}
th {
background-color: #f2f2f2;
}
</style>
colspan
and rowspan
colspan
: Merge columns<td colspan="2">Merged Column</td>
rowspan
: Merge rows<td rowspan="2">Merged Row</td>
<table>
<caption>Student Marks</caption>
...
</table>
<div style="overflow-x:auto;">
<table>
...
</table>
</div>
Q1. Create a basic table with 2 rows and 2 columns.
Q2. Add column headers to a table using <th>
.
Q3. Display a student result table with Roll No, Name, and Marks.
Q4. Style a table with border and padding using CSS.
Q5. Merge two columns using colspan
.
Q6. Merge two rows using rowspan
.
Q7. Add a caption titled “Employee Details” to a table.
Q8. Create a table inside a scrollable div.
Q9. Create a 3×3 multiplication table using HTML.
Q10. Display a monthly calendar using table rows and columns.
Q1: Which tag is used to define a table in HTML?
Q2: Which tag is used to define a row in a table?
Q3: What does the <th> tag represent?
Q4: Which attribute is used to merge two columns?
Q5: Which tag is used for table data (cells)?
Q6: What is the default alignment of text in <th>?
Q7: Which tag is used to give a title to the table?
Q8: What happens when you apply border-collapse: collapse to a table?
Q9: Which CSS property is used to make a table scrollable on small screens?
Q10: Which of the following tags is optional in a table?