Skip to content

Table ​

A responsive data table with a caption, header, row hover and a totals footer.

Installation ​

bash
npx bootcn add table
bash
pnpm dlx bootcn add table
bash
yarn dlx bootcn add table
bash
bunx --bun bootcn add table

The CLI also installs the design tokens and these components: none. It prints the <link> and <script> tags to add to your layout.

Usage ​

Keep the <caption>, <thead> with scope="col" and, where it helps, a row header (<th scope="row">) in each row. .table-responsive lets wide tables scroll sideways on small screens. For sorting, filtering and pagination, use the Data table component.

Accessibility ​

  • The caption names the table; column and row headers are announced with each cell.
  • Row hover is a visual aid only; nothing depends on it.

Dependencies ​

  • Bootstrap 5.3+ CSS.
  • themes/tokens/tokens.css.

Source ​

The exact files the CLI installs (table@1.0.0). View on GitHub · Report an issue

html
<div class="table-responsive">
  <table class="table bootcn-table">
    <caption>
      Your recent invoices.
    </caption>
    <thead>
      <tr>
        <th scope="col">Invoice</th>
        <th scope="col">Status</th>
        <th scope="col">Method</th>
        <th scope="col" class="text-end">Amount</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th scope="row">INV-001</th>
        <td>Paid</td>
        <td>Card</td>
        <td class="text-end">€250.00</td>
      </tr>
      <tr>
        <th scope="row">INV-002</th>
        <td>Pending</td>
        <td>Bank transfer</td>
        <td class="text-end">€150.00</td>
      </tr>
      <tr>
        <th scope="row">INV-003</th>
        <td>Unpaid</td>
        <td>Bank transfer</td>
        <td class="text-end">€350.00</td>
      </tr>
      <tr>
        <th scope="row">INV-004</th>
        <td>Paid</td>
        <td>Card</td>
        <td class="text-end">€450.00</td>
      </tr>
      <tr>
        <th scope="row">INV-005</th>
        <td>Paid</td>
        <td>PayPal</td>
        <td class="text-end">€550.00</td>
      </tr>
    </tbody>
    <tfoot>
      <tr>
        <th scope="row" colspan="3">Total</th>
        <td class="text-end">€1,750.00</td>
      </tr>
    </tfoot>
  </table>
</div>
css
.bootcn-table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--bootcn-foreground);
  --bs-table-border-color: var(--bootcn-border-color);
  --bs-table-hover-bg: var(--bootcn-muted);
  --bs-table-hover-color: var(--bootcn-foreground);

  margin: 0;
  caption-side: bottom;
  font-size: 0.875rem;
}

.bootcn-table > caption {
  padding-top: 1rem;
  color: var(--bootcn-muted-foreground);
  text-align: center;
}

.bootcn-table > :not(caption) > * > * {
  padding: 0.625rem 0.5rem;
  vertical-align: middle;
}

.bootcn-table > thead > tr > th {
  color: var(--bootcn-muted-foreground);
  font-weight: 500;
  white-space: nowrap;
}

.bootcn-table > tbody > tr > th {
  font-weight: 500;
}

.bootcn-table > tbody > tr {
  transition: background-color var(--bootcn-transition);
}

.bootcn-table > tbody > tr:hover > * {
  background-color: var(--bootcn-muted);
}

.bootcn-table > tfoot > tr > * {
  border-bottom: 0;
  background-color: var(--bs-tertiary-bg);
  font-weight: 500;
}

.bootcn-table td,
.bootcn-table th {
  font-variant-numeric: tabular-nums;
}

Released under the MIT License. Not affiliated with Bootstrap or shadcn/ui.