Part 10: Mastering Table Structure & Layout
Senior Full-Stack Developer
Structured data organization
HTML tables allow you to arrange data into rows and columns. They're perfect for displaying structured information like schedules, pricing, and comparisons.
Building blocks of tables
Container for the entire table
Table row - horizontal container
Table header - bold and centered
Table data - regular cell content
| Name | Age | City |
|---|---|---|
| John | 25 | New York |
| Sarah | 30 | London |
Merges cells horizontally
| Merged Header | |
|---|---|
| Cell 1 | Cell 2 |
Merges cells vertically
| Vertical Header | Data A |
|---|---|
| Data B |
Sets background color (deprecated)
| Light Blue | Yellow |
Horizontal alignment (deprecated)
| Left | Center | Right |
left, center, rightSpace between cell content and borders
| More Padding | Around Content |
Space between table cells
| More | Space | Between | Cells |
Table border width
| Thicker | Borders |
Perfect for showcasing product plans and features
| Feature | Basic | Pro | Enterprise |
|---|---|---|---|
| Storage | 5GB | 50GB | Unlimited |
| Users | 1 | 5 | Unlimited |
| Support | Priority | 24/7 Phone | |
| Price | $9.99 | $29.99 | $99.99 |
Ideal for schedules and time-based data
| Time | Monday | Tuesday | Wednesday |
|---|---|---|---|
| 9:00-10:00 | Math | Science | English |
| 10:00-11:00 | History | Art Workshop | Geography |
| 11:00-12:00 | Physics | Chemistry | |
| 12:00-1:00 | Lunch Break | ||
| ID | Name | Department | Salary |
|---|---|---|---|
| 001 | John Smith | Engineering | $85,000 |
| 002 | Sarah Johnson | Marketing | $65,000 |
| Product ID | Name | Category | Quantity |
|---|---|---|---|
| P1001 | Wireless Mouse | Electronics | 150 |
| P1002 | Mechanical Keyboard | Electronics | 75 |
| Question | Yes | No | Undecided |
|---|---|---|---|
| Like our product? | 75% | 15% | 10% |
| Would recommend? | 80% | 12% | 8% |
Modern tables use CSS instead of deprecated HTML attributes for styling:
| Product | Category | Price | Rating |
|---|---|---|---|
| Wireless Earbuds | Electronics | $79.99 | ★★★★☆ |
| Smart Watch | Wearables | $199.99 | ★★★★★ |
| Tablet | Computers | $329.99 | ★★★★☆ |
| Smartphone | Mobile | $699.99 | ★★★★★ |
For mobile devices, tables can be challenging. Here are some solutions:
Always use <th> for header cells and scope attribute for accessibility
Ensure tables work on mobile devices with horizontal scroll or stacked layout
Use CSS instead of deprecated HTML attributes for colors, spacing, and borders
Use <thead>, <tbody>, <tfoot> for better structure and printing
Only use tables for tabular data, not for page layout
Avoid extremely large tables; consider pagination for big datasets
Helps screen readers understand table structure
scope="col" for column headersscope="row" for row headersProvides context for table content
<caption> provides table titleLinks data cells to their headers
Tables for data, CSS for layout
Always use <th> for header cells
Ensure tables work on mobile
Modern CSS instead of deprecated attributes
Tables shouldn't control page structure
Avoid complex table nesting
Avoid bgcolor, align, etc.
Always consider screen readers
You've Learned HTML Tables
table, tr, th, td elements
colspan and rowspan attributes
bgcolor, align, border
cellpadding and cellspacing
Pricing tables, timetables
Accessibility and modern CSS
Build a comprehensive weekly timetable with:
Tables are for tabular data, not page layout
Use CSS instead of deprecated HTML attributes
Always include proper headers and structure
Ensure tables work on all devices
Next: Learn about creating forms, input fields, buttons, and user interaction