Provides a title or description for the table. Critical for accessibility.
<table> ElementThe <table> element represents tabular data — information presented in a two-dimensional table comprised of rows and columns containing cells of data. Tables are essential for displaying structured information like schedules, pricing comparisons, statistical data, and other grid-based content.
<table> <caption>Table description</caption> <thead> <tr> <th>Header 1</th> <th>Header 2</th> </tr> </thead> <tbody> <tr> <td>Data 1</td> <td>Data 2</td> </tr> </tbody> <tfoot> <tr> <td>Footer 1</td> <td>Footer 2</td> </tr> </tfoot></table>A well-structured table consists of several key elements:
Provides a title or description for the table. Critical for accessibility.
Contains header rows that label the columns. Contains the main data rows of the table. Contains footer rows, typically summaries or totals. Defines a table row containing cells. Header cell that labels a row or column. Standard data cell containing information. Define column properties and styling. The Use Do NOT use Use CSS Grid or Flexbox instead for layout. Making tables accessible is crucial for users with screen readers: Tables can be challenging on mobile devices. Here are common patterns: Use Semantic Structure Always use Add a Caption Every table should have a Use Scope Attributes Add Keep It Simple Avoid complex nested structures. Simpler tables are more accessible and maintainable. Test Responsiveness Test your tables on mobile devices and ensure they remain usable. Consider Alternatives For very complex data, consider using interactive components or charts instead. The Attributes
Section titled “Attributes”Global Attributes
Section titled “Global Attributes”<table> element supports all global HTML attributes.Deprecated Attributes
Section titled “Deprecated Attributes”Common Use Cases
Section titled “Common Use Cases”Basic Data Table
Section titled “Basic Data Table”Table with Footer
Section titled “Table with Footer”Striped Table Rows
Section titled “Striped Table Rows”Tables vs. CSS Layout
Section titled “Tables vs. CSS Layout”<table> when you have:
<table> for:
Accessibility Best Practices
Section titled “Accessibility Best Practices”1. Always Include a Caption
Section titled “1. Always Include a Caption”2. Use
Section titled “2. Use <th> with scope Attribute”<th> with scope Attribute3. For Complex Tables, Use
Section titled “3. For Complex Tables, Use headers Attribute”headers Attribute4. Provide Summary for Complex Tables
Section titled “4. Provide Summary for Complex Tables”Responsive Tables
Section titled “Responsive Tables”1. Horizontal Scroll (Simplest)
Section titled “1. Horizontal Scroll (Simplest)”2. Stacked Layout for Mobile
Section titled “2. Stacked Layout for Mobile”Styling Tables with CSS
Section titled “Styling Tables with CSS”Basic Styling
Section titled “Basic Styling”Border Styles
Section titled “Border Styles”Common Patterns
Section titled “Common Patterns”Highlighting on Hover
Section titled “Highlighting on Hover”Alternating Row Colors (Zebra Striping)
Section titled “Alternating Row Colors (Zebra Striping)”Fixed Header
Section titled “Fixed Header”Best Practices
Section titled “Best Practices”<thead>, <tbody>, and <tfoot> to organize your table logically.<caption> describing its contents.scope to <th> elements to indicate whether they label rows or columns.Browser Support
Section titled “Browser Support”<table> element is supported in all browsers:
Related Elements
Section titled “Related Elements”
<caption> - Provides a title or description for the table<thead> - Groups header rows<tbody> - Groups body rows<tfoot> - Groups footer rows<tr> - Defines a table row<th> - Defines a header cell<td> - Defines a data cell<colgroup> - Groups columns for styling<col> - Defines properties for a columnSpecifications
Section titled “Specifications”