Table
A fully customizable, accessible, and responsive table component for displaying structured data.
Introduction
The Table
component provides a responsive, accessible, and customizable way to display tabular data. With full support for sections like headers, bodies, footers, and additional features like captions, this table is designed to be lightweight and flexible.
Example: Basic Table with Images
Name | Location | Status | Balance | |
---|---|---|---|---|
AT Alex Thompson @alexthompson | alex.t@company.com | San Francisco, US | Active | $1,250.00 |
SC Sarah Chen @sarahchen | sarah.c@company.com | Singapore | Active | $600.00 |
MG Maria Garcia @mariagarcia | m.garcia@company.com | Madrid, Spain | Active | $0.00 |
DK David Kim @davidkim | d.kim@company.com | Seoul, KR | Active | -$1,000.00 |
Table with images
Installation
Install the table
component:
Data Table
You can use the <Table />
component to build more complex data tables. Combine it with @tanstack/react-table
to create tables with sorting, filtering and pagination.
Example: Vertical Table (Key-Value pairs)
Name | David Kim |
d.kim@company.com | |
Location | Seoul, KR |
Status | Active |
Balance | -$1,000.00 |
Vertical table
Example: Table with Caption and Footer
Invoice | Status | Method | Amount |
---|---|---|---|
INV001 | Paid | Credit Card | $250.00 |
INV002 | Pending | PayPal | $150.00 |
INV003 | Unpaid | Bank Transfer | $350.00 |
INV004 | Paid | Credit Card | $450.00 |
INV005 | Paid | PayPal | $550.00 |
INV006 | Pending | Bank Transfer | $200.00 |
Total | $1,950.00 |
Table with caption and footer
Example: Complex Browser Compatibility Table
Desktop browsers | Mobile browsers | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox Android | Opera Android | Safari iOS | Samsung Internet | |
container-queries | Supported 105 | Supported 105 | Supported 110 | Supported 91 | Supported 16 | Supported 105 | Supported 110 | Supported 73 | Supported 16 | Supported 20 |
subgrid | Supported 117 | Supported 117 | Supported 71 | Supported 103 | Supported 16 | Supported 117 | Supported 71 | Supported 79 | Supported 16 | Supported 22 |
has-selector | Supported 121 | Supported 121 | Supported 121 | Supported 107 | Supported 15.4 | Supported 121 | Supported 121 | Supported 79 | Supported 15.4 | Not supported No |
Browser compatibility table
File Structure
Component API
Prop | Type | Default |
---|---|---|
Table | React.ForwardRefExoticComponent | - |
TableHeader | React.ForwardRefExoticComponent | - |
TableBody | React.ForwardRefExoticComponent | - |
TableFooter | React.ForwardRefExoticComponent | - |
TableRow | React.ForwardRefExoticComponent | - |
TableCell | React.ForwardRefExoticComponent | - |
TableHead | React.ForwardRefExoticComponent | - |
TableCaption | React.ForwardRefExoticComponent | - |
Installation
Install the Table
component:
Styling Guidelines
The Table component uses semantic HTML elements with sensible defaults, but is designed to be highly customizable via Tailwind classes.
Basic Style Customizations
- Table Width: The table defaults to 100% width but can be constrained with custom classes.
- Cell Padding: Default padding (
p-2
) can be adjusted for density needs. - Row Highlighting: Rows have hover effects by default which can be disabled with
hover:bg-transparent
. - Borders: Row borders are included by default but can be customized.
Advanced Styling Techniques
-
Custom Row Borders:
-
Vertical Text for Headers:
-
Status Indicators:
-
Fixed Column Width:
Usage Patterns
Standard Tables
For most cases, use a standard table structure with headers:
Tables with Footers
Add a footer for summary rows or totals:
Responsive Tables
For tables that might overflow on mobile, use the container’s automatic overflow handling:
Accessibility
The Table component follows best practices for accessibility:
- Semantic Structure: Uses proper HTML table elements (
<table>
,<thead>
,<tbody>
, etc.). - Keyboard Navigation: The table is navigable via keyboard, with cells accessible in a logical order.
- Captions: The
<TableCaption>
component allows adding descriptive text for screen readers. - Row Selection: When implementing selectable rows, use proper ARIA attributes.
- Responsive Design: The container’s overflow handling ensures content remains accessible on small screens.
When using complex tables (like the browser compatibility example), ensure proper ARIA roles and labels are provided, especially for rotated text or icon-only content.
Best Practices
Performance
- For large datasets, consider pagination or virtualization to improve performance.
- Avoid deeply nested content within table cells to maintain rendering efficiency.
Responsive Design
- Consider alternative layouts for mobile displays when tables have many columns.
- Use
className="hidden md:table-cell"
to hide less important columns on mobile. - Consider collapsible rows or card-based layouts for very complex tables on mobile.
User Experience
- Use consistent column alignment (e.g., right-align numerical data).
- Add hover effects for interactive rows, but disable them for header rows.
- Use appropriate spacing and typography to maintain readability.
Conclusion
The Table
component provides a flexible foundation for displaying tabular data in your application. With its modular design, comprehensive styling options, and accessibility features, it’s suitable for a wide range of use cases — from simple data tables to complex interactive displays.
Use the examples provided as a starting point, and customize the component to meet your specific design and functional requirements.