Lab 05: Positioning & Z-index

🎯 Objective

Build semantic HTML tables using <table>, <thead>, <tbody>, <tfoot>, <tr>, <th>, and <td>, with proper accessibility attributes.

📚 Background

HTML tables display tabular data — data with rows and columns. They are NOT for layout (use CSS Grid/Flexbox instead). Proper semantic markup including <thead>, <caption>, and scope attributes makes tables accessible to screen readers.

⏱️ Estimated Time

30 minutes

📋 Prerequisites

  • Labs 1–4 completed

🛠️ Tools Used

  • Python 3, Web browser

🔬 Lab Instructions

Step 1: Create the lab file

Step 2: Build a basic table

💡 scope="col" on <th> helps screen readers understand that the header applies to the column.

Step 3: Add cell spanning

💡 colspan merges cells horizontally; rowspan merges vertically.

Step 4: Add row-level headers

Step 5: Use <colgroup> for column styling

Step 6: Validate the HTML

📸 Verified Output:

Step 7: Make the table responsive

Add to your <style>:

Add data-label attributes to your <td> cells for the mobile labels.

Step 8: View in browser

Open http://localhost:8080/lab05-tables.html.

📸 Verified Output:

  • Striped rows (every other row has light gray background)

  • Blue header row with white text

  • colspan cells visibly span multiple columns

✅ Verification

🚨 Common Mistakes

  • Using tables for page layout — Never. Use CSS Grid or Flexbox

  • Missing <caption> — Reduces accessibility; screen readers announce it

  • Missing scope on <th> — Screen readers can't associate headers with data cells

  • Incorrect colspan/rowspan — Cell count mismatch breaks the table visually

  • No <thead>/<tbody> structure — Makes the table less semantic and harder to style

📝 Summary

You mastered:

  • Table structure: <table>, <thead>, <tbody>, <tfoot>

  • Row/cell elements: <tr>, <th>, <td>

  • Accessibility: <caption>, scope attribute on headers

  • Cell spanning: colspan and rowspan

  • Column styling with <colgroup>

🔗 Further Reading

Last updated