Tables optional

Clean, responsive tables for displaying data with various styling options.

Basic Example

Standard table with clean styling using .focus-table.

Name Email Role Status
John Doe john.doe@example.com Developer Active
Jane Smith jane.smith@example.com Designer Active
Bob Johnson bob.johnson@example.com Manager Inactive
HTML
<table class="focus-table">
  <thead>
    <tr>
      <th>Name</th>
      <th>Email</th>
      <th>Role</th>
      <th>Status</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>John Doe</td>
      <td>john.doe@example.com</td>
      <td>Developer</td>
      <td>Active</td>
    </tr>
  </tbody>
</table>

Striped Table

Use striped tables for long lists with many rows to help users track across columns. The alternating background improves readability and reduces eye strain:

Product Price Quantity Total
Product A $25.00 2 $50.00
Product B $15.00 3 $45.00
Product C $30.00 1 $30.00
Product D $20.00 2 $40.00
HTML
<table class="focus-table focus-table-striped">
  <thead>
    <tr>
      <th>Product</th>
      <th>Price</th>
      <th>Quantity</th>
      <th>Total</th>
    </tr>
  </thead>
  <tbody>
    <!-- rows here -->
  </tbody>
</table>

Bordered Table

Use bordered tables for dense data where clear cell separation is important, like spreadsheets, comparison tables, or data grids. Borders make individual cells easier to distinguish:

ID Task Priority Due Date
1 Update documentation High 2026-01-15
2 Fix bug in login Critical 2026-01-10
3 Review pull requests Medium 2026-01-20
HTML
<table class="focus-table focus-table-bordered">
  <thead>
    <tr>
      <th>ID</th>
      <th>Task</th>
      <th>Priority</th>
      <th>Due Date</th>
    </tr>
  </thead>
  <tbody>
    <!-- rows here -->
  </tbody>
</table>

Compact Table

Use compact tables when space is limited or you need to fit more data on screen. Best for admin panels, dashboards, or data-dense interfaces. Avoid on mobile unless necessary:

Server Status CPU Memory
web-01 Online 45% 2.1 GB
web-02 Online 32% 1.8 GB
db-01 Online 68% 4.5 GB
cache-01 Offline 0% 0 GB
HTML
<table class="focus-table focus-table-compact">
  <thead>
    <tr>
      <th>Server</th>
      <th>Status</th>
      <th>CPU</th>
      <th>Memory</th>
    </tr>
  </thead>
  <tbody>
    <!-- rows here -->
  </tbody>
</table>

Responsive Table

Use focus-table-responsive to contain horizontal scrolling. Add tabindex="0", role="region" and a descriptive label to the wrapper so keyboard users can reach and scroll it. The wrapper remains focusable when all columns fit.

To hide a less important column below 768px, add focus-d-none focus-d-md-table-cell to its header and every corresponding data cell. This example hides Reference and Channel on narrow screens. Hidden cells are unavailable to assistive technology at that width.

Recent orders
Order Customer Status Total Delivery Reference Channel
#10482 Alex Chen Shipped $129.00 Express R-76124 Online
HTML
<div class="focus-table-responsive" role="region" aria-label="Orders table scroll area" tabindex="0">
  <table class="focus-table">
    <caption>Recent orders</caption>
    <thead>
      <tr>
        <th scope="col">Order</th>
        <th scope="col">Customer</th>
        <th scope="col">Status</th>
        <th scope="col">Total</th>
        <th scope="col">Delivery</th>
        <th scope="col" class="focus-d-none focus-d-md-table-cell">Reference</th>
        <th scope="col" class="focus-d-none focus-d-md-table-cell">Channel</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>#10482</td>
        <td>Alex Chen</td>
        <td>Shipped</td>
        <td>$129.00</td>
        <td>Express</td>
        <td class="focus-d-none focus-d-md-table-cell">R-76124</td>
        <td class="focus-d-none focus-d-md-table-cell">Online</td>
      </tr>
    </tbody>
  </table>
</div>

Text Alignment

Align cell content with .text-center and .text-right classes.

Item Quantity Price Total
Widget A 5 $12.99 $64.95
Widget B 3 $8.50 $25.50
Widget C 7 $15.00 $105.00
HTML
<table class="focus-table">
  <thead>
    <tr>
      <th>Item</th>
      <th class="text-center">Quantity</th>
      <th class="text-right">Price</th>
      <th class="text-right">Total</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Widget A</td>
      <td class="text-center">5</td>
      <td class="text-right">$12.99</td>
      <td class="text-right">$64.95</td>
    </tr>
  </tbody>
</table>

Interactive Table Builder

Customize a table and see the code update in real time. If you enable Responsive Wrapper, replace Table scroll area with a label that describes your table.

Column 1 Column 2 Column 3
Data 1-1 Data 1-2 Data 1-3
Data 2-1 Data 2-2 Data 2-3
Data 3-1 Data 3-2 Data 3-3
HTML

Builder Options

Options:

JavaScript API

Add interactive sorting to tables with the FocusUI.Tables.makeSortable() API. Supports automatic number/string detection and toggle between ascending/descending.

Make Table Sortable

Activate a column header button with a click, Enter, or Space to sort.

Alice Johnson 28 New York
Bob Smith 34 Los Angeles
Charlie Brown 22 Chicago
Diana Prince 31 Boston
HTML + JavaScript
<table class="focus-table" id="sortableTable">
  <thead>
    <tr>
      <th scope="col" data-sort="name"><button type="button" class="focus-btn focus-btn-sm focus-btn-outline">Name <span class="focus-table-sort-icon" aria-hidden="true"></span></button></th>
      <th scope="col" data-sort="age"><button type="button" class="focus-btn focus-btn-sm focus-btn-outline">Age <span class="focus-table-sort-icon" aria-hidden="true"></span></button></th>
      <th scope="col" data-sort="city"><button type="button" class="focus-btn focus-btn-sm focus-btn-outline">City <span class="focus-table-sort-icon" aria-hidden="true"></span></button></th>
    </tr>
  </thead>
  <tbody>
    <!-- table rows -->
  </tbody>
</table>

<script>
FocusUI.Tables.makeSortable('#sortableTable')
</script>

With Sort Callback

JavaScript
FocusUI.Tables.makeSortable('#myTable', {
  onSort: function(data) {
    console.log('Sorted by:', data.column, 'in', data.direction, 'order')
    console.log('Rows:', data.rows)
  }
})

Cleanup

Since v2.3.0, repeated calls to a destroyed handle do not affect a later instance of the same table.

JavaScript
const sortable = FocusUI.Tables.makeSortable('#myTable')

sortable.destroy()

Methods

Method Returns Description
Tables.makeSortable(selector, options) Object Make a table sortable. Returns object with destroy() method.

Options

Option Type Default Description
headerSelector string 'th[data-sort]' Selector for sortable column headers
bodySelector string 'tbody' Selector for table body element
sortIcon string Built-in icon Default (unsorted) icon HTML
sortIconAsc string Built-in icon Ascending sort icon HTML
sortIconDesc string Built-in icon Descending sort icon HTML
onSort function null Callback after sorting: ({ column, direction, rows })

The API automatically detects numbers vs strings and sorts accordingly. Add an empty .focus-table-sort-icon element to each sortable header to display the built-in indicators. Existing icon markup is left in place on initialization. Custom icon options continue to accept the restricted <i class="..."></i> format. Use a native button inside each sortable header so Enter and Space dispatch the click the API handles. For formatted currency or dates, sort numbers or timestamps in application state and format them when rendering. The dashboard recipe shows typed sorting.

CSS Classes Reference

Class Description
.focus-table Base table styling with shadow and hover effects
.focus-table-striped Alternating row background colors
.focus-table-bordered Add borders to all table cells
.focus-table-compact Reduced padding for more compact display
.focus-table-responsive Wrapper div enabling horizontal scroll on small screens
.text-center Center-align cell content (on th/td)
.text-right Right-align cell content (on th/td)

Table headings preserve the case in your markup. Set --focus-label-text-transform: uppercase on the component to use uppercase.