Table
µTable provides enhanced table styles for the µCSS framework. It adds hover highlights, striped rows, bordered cells, and compact padding on top of the default table styling.
Usage #
Apply one or more modifier classes directly on the <table> element:
| Name | Role | Status |
|---|---|---|
| Alice | Developer | Active |
| Bob | Designer | Active |
| Charlie | Manager | Away |
<table class="table-hover">
<thead>
<tr><th>Name</th><th>Role</th><th>Status</th></tr>
</thead>
<tbody>
<tr><td>Alice</td><td>Developer</td><td>Active</td></tr>
<tr><td>Bob</td><td>Designer</td><td>Active</td></tr>
<tr><td>Charlie</td><td>Manager</td><td>Away</td></tr>
</tbody>
</table>
Variants #
Hover #
Highlights a row when the user hovers over it.
| Name | Role | Status |
|---|---|---|
| Alice | Developer | Active |
| Bob | Designer | Active |
| Charlie | Manager | Away |
<table class="table-hover">
...
</table>
Striped #
Applies an alternating background on odd rows for better readability. Hidden rows ([hidden]) are automatically skipped in the odd/even alternation, so the striping stays correct when rows are dynamically shown or hidden.
| Name | Role | Status |
|---|---|---|
| Alice | Developer | Active |
| Bob | Designer | Active |
| Charlie | Manager | Away |
<table class="table-striped">
...
</table>
Bordered #
Adds a 1px border around the table and every cell.
| Name | Role | Status |
|---|---|---|
| Alice | Developer | Active |
| Bob | Designer | Active |
| Charlie | Manager | Away |
<table class="table-bordered">
...
</table>
Compact #
Reduces cell padding to 0.25rem 0.5rem for denser data display.
| Name | Role | Status |
|---|---|---|
| Alice | Developer | Active |
| Bob | Designer | Active |
| Charlie | Manager | Away |
<table class="table-compact">
...
</table>
Combining variants #
All modifier classes can be combined freely. Common combinations:
Hover + bordered #
| ID | Name | Role | |
|---|---|---|---|
| 1 | Alice | alice@example.com | Developer |
| 2 | Bob | bob@example.com | Designer |
<table class="table-hover table-bordered">
<thead>
<tr><th>ID</th><th>Name</th><th>Email</th><th>Role</th></tr>
</thead>
<tbody>
<tr><td>1</td><td>Alice</td><td>alice@example.com</td><td>Developer</td></tr>
<tr><td>2</td><td>Bob</td><td>bob@example.com</td><td>Designer</td></tr>
</tbody>
</table>
Compact + bordered #
| Key | Value | Type |
|---|---|---|
| host | localhost | string |
| port | 8080 | integer |
<table class="table-compact table-bordered">
<thead>
<tr><th>Key</th><th>Value</th><th>Type</th></tr>
</thead>
<tbody>
<tr><td>host</td><td>localhost</td><td>string</td></tr>
<tr><td>port</td><td>8080</td><td>integer</td></tr>
</tbody>
</table>
Striped + hover + bordered #
| Name | Role | Status |
|---|---|---|
| Alice | Developer | Active |
| Bob | Designer | Active |
| Charlie | Manager | Away |
<table class="table-striped table-hover table-bordered">
...
</table>
Class reference #
| Class | Effect |
|---|---|
.table-hover | Background highlight on row hover (--mu-secondary-background) |
.table-striped | Alternating background on odd rows (50% --mu-secondary-background) |
.table-bordered | 1px solid border on table, <th>, and <td> |
.table-compact | Reduced padding: 0.25rem 0.5rem |
Responsive tables #
For tables wider than their container, wrap them in a scrollable <div>:
| Name | Role | Status | Location | |
|---|---|---|---|---|
| Alice | Developer | Active | alice@example.com | New York |
| Bob | Designer | Active | bob@example.com | London |
<div style="overflow-x: auto;">
<table class="table-bordered">
...
</table>
</div>
Implementation note #
The base styles set background-color on individual <th> and <td> cells rather than on <tr> rows. For this reason, .table-hover and .table-striped target th and td elements directly instead of tr. This ensures the hover and stripe backgrounds correctly override default cell styles.
The .table-bordered variant uses color-mix() to blend --mu-muted-color (30%) with --mu-muted-border-color (70%) for visible but not heavy cell borders.
Accessibility #
- Use
<caption>to provide a descriptive title for the table. - Use
<thead>,<tbody>, and<tfoot>to group rows semantically. - Use
scope="col"on header cells in<thead>andscope="row"on row headers. - For complex tables, use
aria-describedbyto reference a longer description. - Avoid using tables for layout -- only use them for tabular data.