By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Tables are fundamental structures in HTML used to organize data into rows and columns. Mastering tables is crucial for web design, as they enhance readability and usability. Incorrect table usage can lead to poor layout, inaccessibility, and maintenance issues. For example, a poorly structured table can confuse screen readers, making your website inaccessible to visually impaired users. Understanding table, tr, th, td, colspan, and rowspan is essential for creating effective and accessible web pages.
Example: html <table> <tr> <th>Header 1</th> <th>Header 2</th> </tr> <tr> <td>Data 1</td> <td>Data 2</td> </tr> </table> ⚠️ Common pitfall: Forgetting to close tags can break the table structure.
html <table> <tr> <th>Header 1</th> <th>Header 2</th> </tr> <tr> <td>Data 1</td> <td>Data 2</td> </tr> </table>
Add Multiple Rows and Columns
Example: html <table> <tr> <th>Header 1</th> <th>Header 2</th> <th>Header 3</th> </tr> <tr> <td>Data 1</td> <td>Data 2</td> <td>Data 3</td> </tr> <tr> <td>Data 4</td> <td>Data 5</td> <td>Data 6</td> </tr> </table>
html <table> <tr> <th>Header 1</th> <th>Header 2</th> <th>Header 3</th> </tr> <tr> <td>Data 1</td> <td>Data 2</td> <td>Data 3</td> </tr> <tr> <td>Data 4</td> <td>Data 5</td> <td>Data 6</td> </tr> </table>
Use colspan to Merge Columns
Example: html <table> <tr> <th colspan="2">Header 1</th> <th>Header 2</th> </tr> <tr> <td>Data 1</td> <td>Data 2</td> <td>Data 3</td> </tr> </table> ⚠️ Common pitfall: Incorrect colspan values can misalign the table.
html <table> <tr> <th colspan="2">Header 1</th> <th>Header 2</th> </tr> <tr> <td>Data 1</td> <td>Data 2</td> <td>Data 3</td> </tr> </table>
Use rowspan to Merge Rows
html <table> <tr> <th rowspan="2">Header 1</th> <th>Header 2</th> </tr> <tr> <th>Header 3</th> </tr> <tr> <td>Data 1</td> <td>Data 2</td> </tr> </table>
Experts view tables as structured data containers. They think in terms of data relationships and accessibility. Instead of just filling cells, they consider how the data will be read and used, especially by assistive technologies. They use th and scope attributes to enhance table navigation for screen readers.
Exam trap: Questions may ask to identify the correct header element.
The mistake: Incorrect colspan and rowspan values.
Exam trap: Calculating the correct span values.
The mistake: Forgetting to close table tags.
Exam trap: Identifying incomplete HTML code.
The mistake: Not using the scope attribute.
Scenario: You need to create a table for a weekly schedule with days as headers and activities listed below.Question: Write the HTML code for the table.Solution:1. Define the table with table.2. Create a row for headers with tr and th.3. Add rows for activities with tr and td.Answer:
<table> <tr> <th>Day</th> <th>Monday</th> <th>Tuesday</th> <th>Wednesday</th> </tr> <tr> <td>Activity 1</td> <td>Meeting</td> <td>Lunch</td> <td>Training</td> </tr> <tr> <td>Activity 2</td> <td>Report</td> <td>Meeting</td> <td>Break</td> </tr> </table>
Why it works: It organizes data logically and uses th for headers, improving accessibility.
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.