html table mcq questions basic to advance

HTML tables are a very important topic in website development. Thatโ€™s why we have brought HTML Table MCQ questions for you. By practicing these questions, you can improve your skills effectively.

Q1. Which tag is used first to create a table in HTML?

<table>
<tr>
<td>
<th>
โœ… Correct Answer: <table>

To create a table in HTML, the <table> tag is used first. It defines the beginning of the table structure.

Q2. Why is the <tr> tag used in an HTML table?

To create a column in the table
To create a row in the table
To give a heading in the table
None of these
โœ… Correct Answer: To create a row in the table

The <tr> tag is used to create a row in an HTML table. For every row in the table, a separate <tr> tag is used.

Q3. Which of the following tags is used to give a heading in a table?

<ht>
<td>
<th>
<tr>
โœ… Correct Answer: <th>

The <th> tag is used to define a heading cell in an HTML table. The <td> tag is used for normal data cells, and <ht> is not a valid HTML tag.

Q4. Which of the following tags is NOT used to create a table?

<thead>
<tr>
<td>
<ht>
โœ… Correct Answer: <ht>

The <ht> tag is not a valid HTML tag and is not used in creating a table.

Q5. Which attribute is used to merge two columns in an HTML table?

rowspan
colspan
marge2
colmarge2
โœ… Correct Answer: colspan

The colspan attribute is used to merge two or more columns in an HTML table. It combines multiple columns into a single column.

Q6. If we want to merge two rows in HTML, which is the correct code?

<td spancols='2'>Content</td>
<td colspan='2'>Content</td>
<td spanrow='2'>Content</td>
<td rowspan='2'>Content</td>
โœ… Correct Answer: <td rowspan='2'>Content</td>

The rowspan attribute is used to merge two or more rows in an HTML table. Therefore, the correct code is <td rowspan='2'>Content</td>.

Q7. Which attribute is used to give a border around an HTML table?

frame
square
border
outline
โœ… Correct Answer: border

The border attribute is used inside the <table> tag to add a border around the table.

Q8. What is the function of cellpadding in an HTML table?

Space between cells
Space inside the cell
Merges two cells into one
None of these
โœ… Correct Answer: Space inside the cell

The cellpadding attribute is used to create space between the cell content and the cell border in an HTML table.

Q9. Which of the following is the correct code to set a background color for a table row?

<tr background='black'>
<tr color='green'>
<tr style='background-color: yellow;'>
None of these
โœ… Correct Answer: <tr style='background-color: yellow;'>

To set a background color for a table row, we use CSS with the style attribute, such as <tr style='background-color: yellow;'>. The bgcolor attribute is obsolete in HTML5.

Q10. Why is the <tfoot> tag used in an HTML table?

For the footer section
For note set
To merge columns
To merge rows
โœ… Correct Answer: For the footer section

The <tfoot> tag is used to define the footer section of an HTML table, such as totals or summary information.