Example: Use align="center" for centered marks. Use valign="top" for tall cells.
These attributes are easy to apply, but modern pages prefer CSS for styling.
Proper alignment makes tables neat and readable.
Q5. Why is using <th> in the header row better than using <td>? Explain its benefits.
Answer:
<th> tells the browser that this cell is a header.
Browsers show <th> as bold and centered by default.
It gives meaning to the table. The structure becomes clear.
It helps screen readers understand headings. That improves accessibility.
Sorting and printing can use <thead> and <th> more efficiently.
Using <th> makes the table professional and standard.
High Complexity (Analysis & Scenario-Based)
Q6. You are making a “Class Results” table with a total at the end. Explain how you will use thead, tbody, and tfoot.
Answer:
I will put the headings in <thead> using <th>. Example: Roll No, Name, Marks.
I will put all student rows in <tbody> using <td>.
I will place the total row inside <tfoot>. It may use colspan for labels.
The footer will show “Total Students” and the count in the last cell.
<tfoot> comes after <tbody> in code here, but browsers show it at the bottom.
This structure keeps header, body, and summaryclear and separate.
Q7. A teacher wants a “Subject Wise Marks” table where the main header “Marks” covers two columns: Theory and Practical. How will you design this?
Answer:
In the first header row, I will use
Marks
.
In the same row, other headers like Roll No and Name will be normal <th>.
In the second header row, I will put Theory and Practical as two <th> cells.
All headers will be placed inside <thead> for clarity.
The data rows in <tbody> will have values under Theory and Practical.
This approach uses colspan to group columns and keeps the headings clear.
Q8. Your table looks misaligned after using rowspan in the first column. How will you find and fix the issue?
Answer:
I will first count how many rows the rowspan should cover.
I will check that the merged cell removes the correct number of cells below it.
In each affected row, I will reduce one <td> where rowspan applies.
I will ensure the total number of cells per row matches the header count.
I will test row by row to find where extra or missing cells exist.
Fixing the counts will make columns line up and the table stable.
Q9. A school prints long tables and wants headers on every page. How do thead and th help, and what else would you ensure?
Answer:
<thead> groups the heading rows, so browsers can repeat them when printing.
<th> defines header cells, which improves clarity on each printed page.
I will keep all headings only in <thead> and not mix them into <tbody>.
I will avoid very tall headers so they fit on a page.
I will check that <tfoot> has the summary, printed at the bottom.
This setup makes printing clean, consistent, and readable.
Q10. An old HTML file uses bgcolor, align, width, and height inside <td> and <tr>. The school wants a cleaner structure. What will you keep, and what will you change?
Answer:
I will keep the table structure: <thead>, <tbody>, <tfoot>, <tr>, <th>, <td>.
I will mark headers using <th> to improve meaning.
I will note that bgcolor is deprecated. I will suggest using CSS for colors.
I will reduce align and valign use and prefer CSS for alignment.
I will keep colspan and rowspan because they define layout, not style.
This keeps the HTML semantic and moves design to styles, making code clean.