Tables Exercise
Build structured data tables using table elements and learn how to organize tabular data effectively.
Loading...
Loading exercise code...
Exercise: Master HTML Tables
Objectives
In this exercise, you will:
- Learn the structure of HTML tables (
<table>,<tr>,<td>,<th>) - Understand table sections (
<thead>,<tbody>,<tfoot>) - Practice creating headers and data cells
- Learn how to style tables with CSS
- Understand accessibility best practices for tables
What You’ll Learn
Table Structure:
<table>- The container for all table content<tr>- Table row<td>- Table data cell<th>- Table header cell (automatically bold)<thead>- Groups header rows<tbody>- Groups body rows<tfoot>- Groups footer rows
Table Attributes:
border- Adds borders (number = thickness)cellpadding- Space inside cellscellspacing- Space between cellscolspan- Merge columnsrowspan- Merge rows
Styling Tables:
- Add borders with CSS
borderproperty - Stripe rows with
:nth-child()selector - Highlight headers with background color
- Make tables responsive on mobile
Challenges in This Exercise
- Add more rows - Add more students to the table
- Improve styling - Add CSS to make the table look better
- Add a footer - Use
<tfoot>to add average marks - Make responsive - Handle table on smaller screens
Tips for Success
- Always use
<th>for headers, not<td> - Use
<thead>,<tbody>, and<tfoot>for semantic structure - Avoid using tables for layout - use only for data
- Always provide meaningful table captions
- Test table readability on mobile devices
- Make sure headers clearly describe each column
Next Steps
After completing this exercise:
- Add more data to the table
- Practice using colspan and rowspan
- Try creating different table styles with CSS
- Move on to the Forms exercises!