<table> <tr> <td>Apple</td> <td>Banana</td> </tr> <tr> <td>Cherry</td> <td>Date</td> </tr> </table>
The <tr> tag creates a table row. There are 2 <tr> tags, so 2 rows. Each row has 2 <td> cells, so 2 columns.
The <th> tag defines a header cell in a table. It is bold and centered by default. <td> is for regular cells, <tr> is for rows, and <thead> groups header rows.
table tr td:nth-child(2) selects the second <td> inside each <tr>, which means the second column cells. Option B selects the second <td> of the whole table, not per row. Option B selects all cells in the second row. Option B selects all <td> that are second child of their parent, but without tr context it may select incorrectly.
table-layout: fixed; forces the table to divide width evenly among columns. Setting width: 100% makes the table fill its container. Other options do not evenly space columns: width: auto sizes columns by content, border-collapse affects borders, and display: flex is invalid for tables.
<td> elements?The headers attribute on <td> elements contains a space-separated list of id values of <th> elements that act as headers for that cell. This helps screen readers associate data cells with their headers in complex tables. aria-labelledby is similar but less specific for tables. scope is used on <th> to define header scope. role defines element roles but does not link headers to cells.
Practice
Solution
Step 1: Understand table structure
A table is made of rows and columns. Rows group cells horizontally.Step 2: Identify the row tag
The<tr>tag defines a table row, while<td>and<th>define cells inside rows.Final Answer:
<tr> -> Option AQuick Check:
Row tag = <tr> [OK]
- Confusing <td> as row tag
- Using <th> for rows instead of headers
- Using <table> as row tag
Solution
Step 1: Know header cell tags
Table headers use<th>tags to label columns or rows.Step 2: Check the options
Only<th>Header</th>uses<th>correctly for a header cell.Final Answer:
<th>Header</th> -> Option DQuick Check:
Headers use <th> tags [OK]
- Using <td> for headers
- Using <tr> or <table> as cells
- Missing closing tags
<table>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Alice</td>
<td>30</td>
</tr>
</table>Solution
Step 1: Analyze the table structure
The first row uses<th>for headers 'Name' and 'Age'. The second row uses<td>for data 'Alice' and '30'.Step 2: Understand rendering
This creates a table with two columns labeled 'Name' and 'Age', and one data row with 'Alice' and '30'.Final Answer:
A table with two columns labeled 'Name' and 'Age', and one row with 'Alice' and '30'. -> Option CQuick Check:
Headers + data rows = labeled table [OK]
- Thinking <th> cannot be inside <tr>
- Confusing table with list
- Assuming one column only
<table>
<tr>
<td>Item 1</td>
<tr>
<td>Item 2</td>
</tr>
</table>Solution
Step 1: Check row tags
The first<tr>is opened but not closed before the second<tr>starts.Step 2: Confirm correct nesting
Each<tr>must have a matching closing</tr>. Here, the first row is missing its closing tag.Final Answer:
Missing closing tag for the first <tr>. -> Option BQuick Check:
Everyneeds a closing [OK]
- Ignoring missing closing tags
- Confusing <td> and <th> errors
- Assuming table tag is unclosed
Solution
Step 1: Identify header row requirements
The first row should use<th>tags for all three headers to label columns.Step 2: Check each option
<table> <tr> <th>Product</th> <th>Price</th> <th>Stock</th> </tr> </table>correctly uses<th>inside a<tr>for all headers.<table> <tr> <td>Product</td> <td>Price</td> <td>Stock</td> </tr> </table>uses<td>which is for data cells, not headers.<table> <th>Product</th> <th>Price</th> <th>Stock</th> </table>
places<th>directly inside<table>without a row.<table> <tr> <th>Product</th> <td>Price</td> <td>Stock</td> </tr> </table>mixes<th>and<td>in the header row, which is incorrect.Final Answer:
<pre><table> <tr> <th>Product</th> <th>Price</th> <th>Stock</th> </tr> </table></pre> -> Option AQuick Check:
Headers = all <th> in a <tr> [OK]
- Using <td> for headers
- Placing <th> outside <tr>
- Mixing <th> and <td> in header row
Ready to prove it?
Pass the test and this pattern moves unknown
