HTML Table Interview Questions
Whenever you appear for a web design or full-stack development interview, you are almost always asked questions related to HTML tables. This is because around 99% of websites use tables in some form. In today’s era, websites aim to provide a better user experience by displaying their data in a well-structured and visually appealing manner.
Earlier, interviewers mostly asked basic-level questions. However, nowadays, questions range from basic to advanced levels, especially regarding HTML tables. Therefore, we have compiled a list of important HTML table interview questions that are frequently asked in exams and by various companies.
HTML Table Interview Questions with Answers
Q1. What is the purpose of rowspan in an HTML table?
Answer: It is an attribute in an HTML table. Its function is to merge two or more cells in rows. Suppose we want to show Rahul’s data for both 9th class and 10th class, then we will need to merge Rahul’s cell into two rows, and the data for 9th and 10th will appear in the same row structure.
<table border="1"> <tr> <th>Name</th> <th>Class</th> <th>Roll</th> </tr> <tr> <td rowspan="2">Rahul</td> <td>10</td> <td>3</td> </tr> <tr> <td>11</td> <td>9</td> </tr> </table>
Q2. What is the difference between cellpadding and cellspacing in an HTML table?
Answer: Cellpadding gives space inside the cell around the data. The more value we give, the farther the data moves from the cell border.
<table border="1" cellpadding="20"> <tr> <th>Name</th> <th>Class</th> <th>Roll</th> </tr> <tr> <td>Rahul</td> <td>11th</td> <td>32</td> </tr> <tr> <td>Pankag</td> <td>3rd</td> <td>6</td> </tr> <tr> <td>Sunil</td> <td>8th</td> <td>54</td> </tr> </table>
In cellspacing, space appears outside all the cells. The more value we give, the farther apart the cells will appear.
<table border="1" cellspacing="20"> <tr> <th>Name</th> <th>Class</th> <th>Roll</th> </tr> <tr> <td>Rahul</td> <td>11th</td> <td>32</td> </tr> <tr> <td>Pankag</td> <td>3rd</td> <td>6</td> </tr> <tr> <td>Sunil</td> <td>8th</td> <td>54</td> </tr> </table>
Q3. What is the difference between <th> and <td> tags?
Answer: The <th>
tag is used to give headings to the columns in a table and displays bold text by default. The <td>
tag is used for table data, and its text is not bold. That’s the main difference between them.
Q4. Why are <thead>, <tbody>, and <tfoot> tags used?
Answer:
<thead>
defines the header section of a table and usually contains<th>
tags.<tbody>
contains the main content of the table and uses<td>
tags.<tfoot>
defines the footer of the table, often used for summary rows and also uses<td>
tags.
Q5. How to increase the thickness of the border in an HTML table?
Answer: To increase the border thickness in an HTML table, we use the border
attribute. The higher the value we give, the thicker the border will appear.
<table border="3"> </table>
Useful Table Tips for Interviews
When you appear for an interview, you should not be confused about any tag — make sure all tags are clear to you. And even if you face a question that you are unable to solve, still try to solve it. Many times, interviewers ask questions that even the company itself doesn’t expect to be fully solved. Attempting such questions can give you a positive impression and a plus point.
🔗 Also check: