HTML & CSS Interview Question #21
What are colspan and rowspan in HTML tables?
HTML Fundamentals, Structure, Semantics, Links, Images, Tables & Forms Junior Beginner
Quick Interview Answer
colspan allows a table cell to span multiple columns, while rowspan allows it to span multiple rows. They are useful for representing legitimate grouped relationships in complex tabular data.
Detailed Explanation
colspan allows a table cell to span multiple columns, while rowspan allows it to span multiple rows. They are useful for representing legitimate grouped relationships in complex tabular data.
Excessive spanning can make tables difficult to understand and less accessible, so the structure should remain as simple as the data permits. Header cells and scope relationships should still be designed carefully.
Code Example
<table>
<tr>
<th rowspan="2">Subject</th>
<th colspan="2">Questions</th>
</tr>
<tr>
<th>Beginner</th>
<th>Advanced</th>
</tr>
</table>