The New CSS

Tables

The tables addon provides styled table classes with variants for striped rows, hover highlights, bordered cells, compact spacing, fixed layout, responsive horizontal scrolling, and cell-level alignment utilities.

Installation

npm install @thenewcss/tables

Basic Table

Apply .table for full-width styling with consistent padding and bottom borders.

NameRoleStatusDate
Alice MartinDesignerActiveJan 15, 2025
Bob ChenDeveloperActiveFeb 02, 2025
Carol DavisManagerOn LeaveMar 10, 2025
Dan WilsonQA EngineerActiveApr 22, 2025
<table class="table"> <thead> <tr> <th>Name</th> <th>Role</th> <th>Status</th> <th>Date</th> </tr> </thead> <tbody> <tr> <td>Alice Martin</td> <td>Designer</td> <td>Active</td> <td>Jan 15, 2025</td> </tr> <tr> <td>Bob Chen</td> <td>Developer</td> <td>Active</td> <td>Feb 02, 2025</td> </tr> </tbody> </table>

Striped Table

Add .table-striped for alternating row backgrounds on even rows.

NameRoleStatusDate
Alice MartinDesignerActiveJan 15, 2025
Bob ChenDeveloperActiveFeb 02, 2025
Carol DavisManagerOn LeaveMar 10, 2025
Dan WilsonQA EngineerActiveApr 22, 2025
<table class="table table-striped"> <thead> <tr> <th>Name</th> <th>Role</th> <th>Status</th> <th>Date</th> </tr> </thead> <tbody> <tr><td>Alice Martin</td><td>Designer</td><td>Active</td><td>Jan 15, 2025</td></tr> <tr><td>Bob Chen</td><td>Developer</td><td>Active</td><td>Feb 02, 2025</td></tr> <tr><td>Carol Davis</td><td>Manager</td><td>On Leave</td><td>Mar 10, 2025</td></tr> </tbody> </table>

Hover Table

Add .table-hover to highlight rows on hover.

NameRoleStatusDate
Alice MartinDesignerActiveJan 15, 2025
Bob ChenDeveloperActiveFeb 02, 2025
Carol DavisManagerOn LeaveMar 10, 2025
Dan WilsonQA EngineerActiveApr 22, 2025
<table class="table table-hover"> ... </table>

Bordered Table

Add .table-bordered for borders on the table and all cells.

NameRoleStatusDate
Alice MartinDesignerActiveJan 15, 2025
Bob ChenDeveloperActiveFeb 02, 2025
Carol DavisManagerOn LeaveMar 10, 2025
Dan WilsonQA EngineerActiveApr 22, 2025
<table class="table table-bordered"> ... </table>

Compact Table

Add .table-compact to reduce cell padding for denser data display.

NameRoleStatusDate
Alice MartinDesignerActiveJan 15, 2025
Bob ChenDeveloperActiveFeb 02, 2025
Carol DavisManagerOn LeaveMar 10, 2025
Dan WilsonQA EngineerActiveApr 22, 2025
<table class="table table-compact"> ... </table>

Combined: Striped + Hover

Variants compose naturally. Combine .table-striped and .table-hover for striped rows with hover highlights.

NameRoleStatusDate
Alice MartinDesignerActiveJan 15, 2025
Bob ChenDeveloperActiveFeb 02, 2025
Carol DavisManagerOn LeaveMar 10, 2025
Dan WilsonQA EngineerActiveApr 22, 2025
<table class="table table-striped table-hover"> ... </table>

Responsive Table

Wrap a table in a .table-responsive container for horizontal scrolling on narrow viewports.

IDNameEmailRoleDepartmentLocationStatusStart Date
001Alice Martin[email protected]DesignerProductNew YorkActiveJan 15, 2025
002Bob Chen[email protected]DeveloperEngineeringSan FranciscoActiveFeb 02, 2025
003Carol Davis[email protected]ManagerOperationsChicagoOn LeaveMar 10, 2025
<div class="table-responsive"> <table class="table table-bordered"> <thead> <tr> <th>ID</th> <th>Name</th> <th>Email</th> <th>Role</th> <th>Department</th> <th>Location</th> <th>Status</th> <th>Start Date</th> </tr> </thead> <tbody> <tr> <td>001</td> <td class="cell-nowrap">Alice Martin</td> <td class="cell-nowrap">[email protected]</td> <td>Designer</td> <td>Product</td> <td>New York</td> <td>Active</td> <td class="cell-nowrap">Jan 15, 2025</td> </tr> </tbody> </table> </div>

Cell Utilities

Apply cell utility classes directly to th or td elements for alignment, wrapping, and truncation control.

ProductQuantityPriceShip Date
Premium Wireless Bluetooth Headphones with Noise Cancellation42$129.99Jan 15, 2025
Ergonomic Mechanical Keyboard with Cherry MX Blue Switches18$89.50Feb 02, 2025
Ultra-Slim USB-C Docking Station with Dual Monitor Support7$249.00Mar 10, 2025
<table class="table table-bordered"> <thead> <tr> <th>Product</th> <th class="cell-center">Quantity</th> <th class="cell-right">Price</th> <th class="cell-nowrap">Ship Date</th> </tr> </thead> <tbody> <tr> <td class="cell-truncate" style="max-width: 150px"> Premium Wireless Bluetooth Headphones... </td> <td class="cell-center cell-middle">42</td> <td class="cell-right">$129.99</td> <td class="cell-nowrap">Jan 15, 2025</td> </tr> </tbody> </table>

Class Reference

Base

ClassDescription
.tableWidth 100%, border-collapse, font-size 0.875rem, text-align start. th gets font-weight 600, padding 0.75rem/1rem, border-bottom 2px gray-200. td gets padding 0.75rem/1rem, border-bottom 1px gray-200.

Variants

ClassDescription
.table-stripedEven rows get a gray-50 background
.table-hoverRows get a gray-100 background on hover
.table-bordered1px gray-200 border on the table and all cells
.table-compactReduced cell padding (0.5rem/0.75rem)
.table-fixedSets table-layout to fixed for equal-width columns

Responsive

ClassDescription
.table-responsiveOverflow-x auto wrapper for horizontal scrolling on narrow viewports

Cell Utilities

ClassDescription
.cell-nowrapPrevents text wrapping inside the cell
.cell-truncateTruncates overflowing text with an ellipsis (max-width 0, overflow hidden)
.cell-centerCenters text horizontally (text-align center)
.cell-rightRight-aligns text (text-align end)
.cell-middleVertically centers cell content (vertical-align middle)