# Use semantic table markup for screen readers > Data tables use proper semantic markup with headers, captions, and scope attributes for screen reader accessibility. **Priority:** medium · **Difficulty:** intermediate · **Time:** 20 min --- Proper table markup enables screen readers to announce header-cell relationships, making data understandable. ## Code Example ```html
Q1 2024 Sales by Region
Region January February March
North $12,000 $14,500 $13,200
South $9,800 $11,000 $10,500
``` ## Why It Matters Screen readers read table data cell-by-cell—without proper headers, users hear meaningless numbers without context. 'Row 3, Column 2: $99' vs just '$99'. ## Scope Attribute | Value | Use When | |-------|----------| | `scope="col"` | Header applies to column below | | `scope="row"` | Header applies to row beside it | | `scope="colgroup"` | Header spans multiple columns | | `scope="rowgroup"` | Header spans multiple rows | ## Complex Tables with Headers Attribute ```html
Sales Report
Region Q1 Q2
Units Revenue Units Revenue
North 150 $15,000 180 $18,000
``` ## React Table Component ```tsx interface Column{caption} {columns.map(col => ( {col.header} ))} {data.map((row, i) => ( {columns.map(col => { const isRowHeader = col.key === rowHeader const Tag = isRowHeader ? 'th' : 'td' return ( {String(row[col.key])} ) })} ))} ) } ``` ## Responsive Tables ```html
``` ```css .table-wrapper { overflow-x: auto; max-width: 100%; } /* Focus indicator for keyboard users scrolling */ .table-wrapper:focus { outline: 2px solid #005fcc; } ``` ## Exceptions - Simple data tables can sometimes fail more from missing header relationships than from missing enhancements such as captions or mobile wrappers, so prioritize the strongest semantic issue. - Do not convert layout structures into data-table markup just to satisfy a rule; the correct fix may be to remove table semantics entirely. - When several table-accessibility issues overlap, resolve the header-cell relationship first because downstream announcements depend on it. ## Verification ### Automated Checks - Use browser accessibility tooling, axe, Lighthouse, or equivalent automated checks against a representative rendered state. ### Manual Checks - Use screen reader table navigation (Ctrl+Alt+Arrow keys in NVDA) - Verify headers are announced with each cell - Check caption describes the table purpose - Confirm table is not used for layout