HTML5: How to group the header content in a table?
Solution:
HTML Code:
<!DOCTYPE html><!-- Define document type as HTML -->
<html><!-- Begin HTML document -->
<head><!-- Start of document header -->
<meta charset="utf-8"><!-- Define character encoding -->
<title>How to group the header content in a table</title><!-- Title of the HTML page -->
</head><!-- End of document header -->
<body><!-- Start of document body -->
<table border="1"><!-- Table element with border attribute -->
<thead><!-- Table header section -->
<tr><!-- Table row element -->
<th>Student code</th><!-- Table header cell for "Student code" -->
<th>% of marks</th><!-- Table header cell for "% of marks" -->
</tr><!-- End of table row -->
</thead><!-- End of table header section -->
<tr><!-- Table row element -->
<td>S001</td><!-- Table data cell with content "S001" -->
<td>85</td><!-- Table data cell with content "85" -->
</tr><!-- End of table row -->
<tr><!-- Table row element -->
<td>S002</td><!-- Table data cell with content "S002" -->
<td>86</td><!-- Table data cell with content "86" -->
</tr><!-- End of table row -->
<tr><!-- Table row element -->
<td>S003</td><!-- Table data cell with content "S003" -->
<td>72</td><!-- Table data cell with content "72" -->
</tr><!-- End of table row -->
<tr><!-- Table row element -->
<td>S004</td><!-- Table data cell with content "S004" -->
<td>89</td><!-- Table data cell with content "89" -->
</tr><!-- End of table row -->
</table><!-- End of table -->
</body><!-- End of document body -->
</html><!-- End of HTML document -->
Explanation:
- This HTML code defines a webpage with a table displaying student information.
- The <table> tag creates a table structure with a border attribute.
- The <thead> tag defines the header section of the table.
- Within the <thead> section, a <tr> tag creates a row, and <th> tags create header cells for "Student code" and "% of marks".
- The <tbody> section contains the rows of data, each represented by a <tr> tag.
- Within each data row, <td> tags create data cells with specific content representing student codes and percentages of marks.
Live Demo:
See the Pen thead-answer by w3resource (@w3resource) on CodePen.
See the solution in the browser
Supported browser
Yes | Yes | Yes | Yes | Yes |
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics