Question:easy

Write the HTML code to create a table with 2 rows and 2 columns and a border of 2. The first row should be the table header containing Roll No and Name, and the second row should contain the values 1 and Rahul respectively.

Show Hint

Start with the table tag and its border attribute, then use th cells for the first row and td cells for the second.
Updated On: Nov 3, 2026
Show Solution

Solution and Explanation

Step 1: Use the grouped table layout:
A table can be split into a head part and a body part with <thead> and <tbody>. This matches the question well: the first row is the header and the second row is the data. The border is still set on the <table> tag.

Step 2: Write the header group:
Inside <thead> we put one row of two <th> cells holding Roll No and Name.

Step 3: Write the body group and join it up:
Inside <tbody> we put one row of two <td> cells holding 1 and Rahul. The complete code is below.
<table border="2">
  <thead>
    <tr><th>Roll No</th><th>Name</th></tr>
  </thead>
  <tbody>
    <tr><td>1</td><td>Rahul</td></tr>
  </tbody>
</table>


Step 4: Count and verify:
Rows: one in thead plus one in tbody, which is 2. Columns: two cells in each row, which is 2. Border: border="2". Header text sits in th cells and the values sit in td cells, as the question asks. The simpler form without thead and tbody is also correct.

Final Answer:
The table has a th header row and a td data row with border 2. \[ \boxed{\text{table border 2: header Roll No, Name; row 1, Rahul}} \]
Was this answer helpful?
0