Skip to main content

Table

Overview​

The Table component and its subcomponents provide a highly composable, Bulma-styled table system for React.

You get full access to Bulma’s table features—borders, stripes, narrow cells, hover effects, responsive scroll, cell/row coloring, and more—using idiomatic React patterns. Bulma helper props for spacing and text color are supported.

info

Use the full suite: Table, Thead, Tbody, Tfoot, Tr, Th, and Td for maximum flexibility and Bulma compatibility.


Import​

import {
Table,
Thead,
Tbody,
Tfoot,
Tr,
Th,
Td,
} from '@allxsmith/bestax-bulma';

Usage​

Default Table​

To create a basic table, use the Table component along with its subcomponents: Thead, Tbody, Tr, Th, and Td. This approach provides a clear, semantic structure for your data and leverages Bulma's default table styling. Use this pattern for any standard tabular data display in your application.

<Table>
  <Thead>
    <Tr>
      <Th>Name</Th>
      <Th>Age</Th>
      <Th>Role</Th>
    </Tr>
  </Thead>
  <Tbody>
    <Tr>
      <Td>Alice</Td>
      <Td>30</Td>
      <Td>Engineer</Td>
    </Tr>
    <Tr>
      <Td>Bob</Td>
      <Td>28</Td>
      <Td>Designer</Td>
    </Tr>
  </Tbody>
</Table>

All Modifiers​

Showcase the full range of table customization by combining multiple props on the Table component. Use isBordered to add borders, isStriped for zebra-striping, isNarrow for compact cells, isHoverable for row hover effects, isFullwidth to stretch the table to its container, and isResponsive for horizontal scrolling on small screens. These modifiers can be mixed and matched to achieve the exact look and behavior you need.

<Table
  isBordered
  isStriped
  isNarrow
  isHoverable
  isFullwidth
  isResponsive
  aria-label="Every modifier"
>
  <Thead>
    <Tr>
      <Th>Column 1</Th>
      <Th>Column 2</Th>
    </Tr>
  </Thead>
  <Tbody>
    <Tr>
      <Td>Cell 1</Td>
      <Td>Cell 2</Td>
    </Tr>
    <Tr>
      <Td>Cell 3</Td>
      <Td>Cell 4</Td>
    </Tr>
  </Tbody>
</Table>

Responsive Table (horizontal scroll on mobile)​

Enable the isResponsive prop to make your table horizontally scrollable on small screens, so a wide table with many columns stays readable on a phone without breaking the layout or hiding data.

Name the table with aria-label, or with aria-labelledby pointing at a heading or at its <caption>'s id. While the table is wider than its container, the container is a tab stop named after the table, as Accessibility says.

<Table isResponsive aria-label="Twenty columns">
  <Thead>
    <Tr>
      {Array.from({ length: 20 }, (_, i) => (
        <Th key={`col-${i + 1}`}>Column {i + 1}</Th>
      ))}
    </Tr>
  </Thead>
  <Tbody>
    {Array.from({ length: 2 }, (_, row) => (
      <Tr key={row}>
        {Array.from({ length: 20 }, (_, col) => (
          <Td key={`cell-${row + 1}-${col + 1}`}>
            Cell {row + 1}-{col + 1}
          </Td>
        ))}
      </Tr>
    ))}
  </Tbody>
</Table>

Colored Cells​

Apply the color prop to individual Td cells to use Bulma's color modifiers. This is helpful for highlighting important data, categorizing information, or simply making your tables more visually engaging. You can use colors like primary, success, warning, danger, info, and more.

Tr and Th take the same colors. They are exported as the validTableColors tuple, for building a color picker or checking a value that arrives at runtime. See valid value constants.

<Table isBordered isFullwidth>
  <Thead>
    <Tr>
      <Th>Cell Color</Th>
      <Th>Example</Th>
    </Tr>
  </Thead>
  <Tbody>
    <Tr>
      <Td>Primary</Td>
      <Td color="primary">Primary Colored Cell</Td>
    </Tr>
    <Tr>
      <Td>Success</Td>
      <Td color="success">Success Colored Cell</Td>
    </Tr>
    {/* ...and so on for link, warning, danger, info, black, dark, light, white */}
  </Tbody>
</Table>

Highlighted Row​

Use the isSelected prop on a Tr to highlight a row, such as the reader's own team or a search result. The highlight is a look only, which a screen reader doesn't announce and some readers can't tell from the other rows, so say in the row why it stands out, as "(your team)" does here. Each team's name is the row's header (Th with scope="row"), which a screen reader announces as it moves into the row. For rows a user picks, give each one a checkbox, as in A Column of Checkboxes.

<Table isFullwidth>
  <Thead>
    <Tr>
      <Th>Team</Th>
      <Th>Wins</Th>
      <Th>Losses</Th>
    </Tr>
  </Thead>
  <Tbody>
    <Tr isSelected>
      <Th scope="row">Ice Wolves (your team)</Th>
      <Td>32</Td>
      <Td>8</Td>
    </Tr>
    <Tr>
      <Th scope="row">Frost Giants</Th>
      <Td>30</Td>
      <Td>9</Td>
    </Tr>
  </Tbody>
</Table>

Custom Alignment and Width​

To control the alignment and width of table header cells, use the isAligned and width props on the Th component. Set isAligned to left, right, or centered to adjust text alignment, and use width with a number or string (e.g., width={200} or width="100px") to specify the column width. This is useful for formatting tables with specific layout requirements or for emphasizing certain columns.

Td takes the same isAligned values, so a column's body cells can line up with its header. A style on a Th keeps its width, and a width inside that style wins.

<Table>
  <Thead>
    <Tr>
      <Th isAligned="left" width={200}>
        Name
      </Th>
      <Th isAligned="right">Score</Th>
    </Tr>
  </Thead>
  <Tbody>
    <Tr>
      <Td isAligned="left">Jane Doe</Td>
      <Td isAligned="right">98</Td>
    </Tr>
  </Tbody>
</Table>

A Column of Checkboxes​

isNarrow on a Th or Td shrinks the cell to its content and keeps it on one line, Bulma's is-narrow cell, which suits a column of checkboxes or actions. It isn't the table's own isNarrow, which tightens every cell's padding. isVcentered centers a cell's content vertically, where cells otherwise sit at the top.

isSelected is a look only, so a row picked for an action needs a checkbox named for it, as here. A bestax Checkbox or Radio placed straight in a selected row's cell takes the row's text color, so a checked one still shows on the row's fill. One in a menu or a table nested in the cell, or in a cell or a row with a color of its own, keeps its own colors, since it sits on that surface instead.

function example() {
  const teams = ['Ice Wolves', 'Frost Giants', 'Snow Owls'];
  const [picked, setPicked] = useState(['Ice Wolves']);
  const toggle = (team: string) =>
    setPicked(current =>
      current.includes(team)
        ? current.filter(name => name !== team)
        : [...current, team]
    );

  return (
    <Table isFullwidth>
      <Thead>
        <Tr>
          <Th isNarrow>
            <Span visibility="sr-only">Picked</Span>
          </Th>
          <Th>Team</Th>
        </Tr>
      </Thead>
      <Tbody>
        {teams.map(team => (
          <Tr key={team} isSelected={picked.includes(team)}>
            <Td isNarrow isVcentered>
              <Checkbox
                aria-label={`Pick ${team}`}
                checked={picked.includes(team)}
                onChange={() => toggle(team)}
              />
            </Td>
            <Th scope="row" isVcentered>
              {team}
            </Th>
          </Tr>
        ))}
      </Tbody>
    </Table>
  );
}


Compound (dot-notation) usage​

Every table sub-component is also available as a static on Table under its exact export name — Table.Thead, Table.Tbody, Table.Tfoot, Table.Tr, Table.Th, and Table.Td — so a full table can be composed from the single Table import.

<Table isStriped>
  <Table.Thead>
    <Table.Tr>
      <Table.Th>Team</Table.Th>
      <Table.Th>Points</Table.Th>
    </Table.Tr>
  </Table.Thead>
  <Table.Tbody>
    <Table.Tr>
      <Table.Td>Maple Leafs</Table.Td>
      <Table.Td>98</Table.Td>
    </Table.Tr>
  </Table.Tbody>
</Table>


Accessibility​

  • Semantics: Uses <table>, <thead>, <tbody>, <tfoot>, <tr>, <th>, and <td>—all proper HTML table elements.
  • Responsive: with isResponsive, the table is wrapped in Bulma's scrollable .table-container. While the table overflows it, the container is a region with a tab stop, named by the table's own aria-label or aria-labelledby, so a keyboard user can reach and scroll it, Safari included. The elements/table partial, which bestax.css and extras.css carry, draws Bulma's focus ring just inside it on keyboard focus. While the table fits, it's a plain div with no tab stop, though one that has focus keeps its tab stop until focus leaves. A development build warns when a table overflows with no name. Without isResponsive the table has no scroll box of its own. With Bulma's default overflow-x: hidden on the page, a table wider than a narrow screen then has its last columns cut off: a pointer can't scroll to them, and keyboard focus moving into one can scroll the page sideways, where a pointer can't scroll it back. WCAG's Reflow criterion (1.4.10) allows a data table to scroll sideways instead.
  • Forced colors: Bulma marks a selected row or cell (Tr isSelected, or a cell with Bulma's is-selected class) with a fill and a text color, which forced colors replaces, so there the elements/table partial draws a double line just inside it in the system's highlight color, which moves nothing. A selected row or cell given a tabIndex keeps the double line while it has keyboard focus, in the system's text color, so it still reads as selected and the focus shows.
  • Screen Readers: Always use <Th> for header cells, and provide descriptive column headings. Make the cell that names a row its header too (Th with scope="row").
  • Selected rows: isSelected is a look, which assistive tech doesn't announce. Say in a highlighted row why it stands out, as in Highlighted Row, and give rows a user picks a checkbox named for the row, as in A Column of Checkboxes.
  • Right to left: with bestax.css and its variants, a header cell aligns to the start of the line, as the body cells do, so on a right-to-left page both sit on the right. They build Bulma with $table-cell-text-align: start, where Bulma's own default, in the table below, is left. With extras.css and a Bulma of your own, set $table-cell-text-align: start in your Bulma build, or --bulma-table-cell-text-align: start on the table, to get the same. isAligned or an align attribute still sets a cell's own alignment.
tip

For responsive tables, ensure your column headers are clear and concise for small screens.


  • Block: For spacing and grouping tables.
  • Helper Props: Bulma helper props for spacing, color, etc.

Additional Resources​


Props​

Table​

PropTypeDefaultDescription
classNamestring—Additional CSS classes to apply.
isBorderedbooleanfalseAdds borders to all cells.
isStripedbooleanfalseAdds zebra-striping to rows.
isNarrowbooleanfalseMakes the table more compact by cutting cell padding in half.
isHoverablebooleanfalseAdds a hover effect on rows.
isFullwidthbooleanfalseMakes the table span the full width of its parent.
isFullWidthbooleanfalseDeprecated. Use isFullwidth instead — isFullwidth wins if both are set. Makes the table span the full width of its parent.
isResponsivebooleanfalseWraps the table in Bulma's .table-container, which scrolls it sideways when it's wider than its parent. Off unless set, and without it the table has no scroll box of its own, so one wider than its parent overflows it, and Bulma's default overflow-x: hidden on the page cuts off what runs past a narrow screen. While the table overflows the container, the container is a region you can tab to and scroll by keyboard, named by the table's own aria-label or aria-labelledby, so name the table with one of them; a development build warns when it overflows with neither. While the table fits, the container is a plain div with no tab stop, though one that has focus keeps its tab stop until focus leaves.
childrenReact.ReactNode—Table content (should use subcomponents).
...All standard <table> attributes and Bulma helper props—See Helper Props

Subcomponents:

  • Table.Thead: Thead component for rendering a styled Bulma table header. Supports Bulma helper classes for additional styling.
  • Table.Tbody: Tbody component for rendering a styled Bulma table body. Supports Bulma helper classes for additional styling.
  • Table.Tfoot: Tfoot component for rendering a styled Bulma table footer. Supports Bulma helper classes for additional styling.
  • Table.Tr: Tr component for rendering a styled Bulma table row. Supports the is-selected modifier and color modifiers.
  • Table.Th: Th component for rendering a styled Bulma table header cell. Supports alignment, width, narrow and vertically centered cells, and color modifiers.
  • Table.Td: Td component for rendering a styled Bulma table cell. Supports alignment, narrow and vertically centered cells, Bulma color modifiers, and helper classes for additional styling.

Table.Thead​

PropTypeDefaultDescription
classNamestring—Additional CSS classes to apply.
childrenReact.ReactNode—Table header content (rows).
...All standard <thead>/<tbody> attributes and Bulma helper props—See Helper Props

Table.Tbody​

PropTypeDefaultDescription
classNamestring—Additional CSS classes to apply.
childrenReact.ReactNode—Table body content (rows).
...All standard <thead>/<tbody> attributes and Bulma helper props—See Helper Props

Table.Tfoot​

PropTypeDefaultDescription
classNamestring—Additional CSS classes to apply.
childrenReact.ReactNode—Table footer content (rows).
...All standard <thead>/<tbody> attributes and Bulma helper props—See Helper Props

Table.Tr​

PropTypeDefaultDescription
classNamestring—Additional CSS classes to apply.
isSelectedbooleanfalseWhether the row is selected (adds Bulma's is-selected class). It's a look only: it says nothing to assistive tech, so pair it with a checkbox named for the row when the selection matters, and say in the row why it stands out when it marks something else, such as a search result. Forced colors replaces its fill, so there the elements/table partial draws a double line just inside the row's edge in the system's highlight color instead. A bestax Checkbox or Radio placed straight in one of the row's cells takes the row's text color, so a checked one shows on the row's fill. One in a menu or a table nested in a cell, or in a cell with a color of its own, keeps its own colors, since it sits on that surface instead, and so does every one in a row with a color, whose cells paint that color over the fill.
colorTableColor—Bulma color modifier for the table row.
childrenReact.ReactNode—Table row content (cells).
...All standard <tr> attributes and Bulma helper props—See Helper Props

Types:

  • TableColor: 'primary' | 'link' | 'info' | 'success' | 'warning' | 'danger' | 'black' | 'dark' | 'light' | 'white' — The color values Tr, Th and Td accept, typed from validTableColors.

Table.Th​

PropTypeDefaultDescription
classNamestring—Additional CSS classes to apply.
isAligned'left' | 'right' | 'centered'—Text alignment for the header cell ('left', 'right', 'centered'). Without it, bestax.css and its variants align a header to the start of the line, as the body cells are, so it sits on the right on a right-to-left page.
isNarrowbooleanfalseShrinks the cell to its content and keeps that on one line (Bulma's is-narrow), as for a column of checkboxes or actions. Not the table's own isNarrow, which tightens every cell's padding.
isVcenteredbooleanfalseCenters the content vertically (Bulma's is-vcentered). Cells sit at the top otherwise.
widthstring | number—Width of the header cell (e.g., '100px' or 100), written into its style. A style passed as well keeps it, and a width that style sets wins.
colorTableColor—Bulma color modifier for the header cell.
childrenReact.ReactNode—Table header cell content.
...All standard <td>/<th> attributes and Bulma helper props—See Helper Props

Types:

  • TableColor: 'primary' | 'link' | 'info' | 'success' | 'warning' | 'danger' | 'black' | 'dark' | 'light' | 'white' — The color values Tr, Th and Td accept, typed from validTableColors.

Table.Td​

PropTypeDefaultDescription
classNamestring—Additional CSS classes to apply.
isAligned'left' | 'right' | 'centered'—Text alignment for the table cell ('left', 'right', 'centered').
isNarrowbooleanfalseShrinks the cell to its content and keeps that on one line (Bulma's is-narrow), as for a column of checkboxes or actions. Not the table's own isNarrow, which tightens every cell's padding.
isVcenteredbooleanfalseCenters the content vertically (Bulma's is-vcentered). Cells sit at the top otherwise.
colorTableColor—Bulma color modifier for the table cell.
childrenReact.ReactNode—Table cell content.
...All standard <td>/<th> attributes and Bulma helper props—See Helper Props

Types:

  • TableColor: 'primary' | 'link' | 'info' | 'success' | 'warning' | 'danger' | 'black' | 'dark' | 'light' | 'white' — The color values Tr, Th and Td accept, typed from validTableColors.

CSS & Sass Variables​

Table registers these variables on its own .table element. Override them there (or via className) — a value set on an ancestor is only inherited, and loses to the component-level declaration. See Theme.

CSS VariableSass VariableDefault
--bulma-table-color$table-colorvar(--bulma-text-strong)
--bulma-table-background-color$table-background-colorvar(--bulma-scheme-main)
--bulma-table-cell-border-color$table-cell-border-colorvar(--bulma-border)
--bulma-table-cell-border-style$table-cell-border-stylesolid
--bulma-table-cell-border-width$table-cell-border-width0 0 1px
--bulma-table-cell-padding$table-cell-padding0.5em 0.75em
--bulma-table-cell-heading-color$table-cell-heading-colorvar(--bulma-text-strong)
--bulma-table-cell-text-align$table-cell-text-alignleft
--bulma-table-head-cell-border-width$table-head-cell-border-width0 0 2px
--bulma-table-head-cell-color$table-head-cell-colorvar(--bulma-text-strong)
--bulma-table-foot-cell-border-width$table-foot-cell-border-width2px 0 0
--bulma-table-foot-cell-color$table-foot-cell-colorvar(--bulma-text-strong)
--bulma-table-head-background-color$table-head-background-colortransparent
--bulma-table-body-background-color$table-body-background-colortransparent
--bulma-table-foot-background-color$table-foot-background-colortransparent
--bulma-table-row-hover-background-color$table-row-hover-background-colorvar(--bulma-scheme-main-bis)
--bulma-table-row-active-background-color$table-row-active-background-colorvar(--bulma-primary)
--bulma-table-row-active-color$table-row-active-colorvar(--bulma-primary-invert)
--bulma-table-striped-row-even-background-color$table-striped-row-even-background-colorvar(--bulma-scheme-main-bis)
--bulma-table-striped-row-even-hover-background-color$table-striped-row-even-hover-background-colorvar(--bulma-scheme-main-ter)