Skip to content

Layout Components

[05] Layout Components

Table

Renders semantic table markup with Table, Thead, Tbody, Tfoot, Tr, Th, Td, and Caption. The size prop cascades from the table to every cell, and a cell or row can override it.

SourceEdit this page

Use Table for data that readers compare across rows and down columns, such as a price list, a schedule or an order summary. To place cards or tiles in columns, use Grid; for a single run of items, one per line, use List.

Basic usage

Compose a table from Table, Thead, Tbody, Tr, Th, and Td. Header cells (Th) render semibold with muted text, and every cell gets a bottom row rule. Table defaults to sm, wFull, noBorder, and fontSans. Add scope="col" to header cells so assistive technology associates each column with its data.

ServiceRegionLatency
api-gatewayeurope-west42ms
authus-east88ms
<Table>
<Thead>
<Tr>
<Th scope="col">Service</Th>
<Th scope="col">Region</Th>
<Th scope="col" textRight>Latency</Th>
</Tr>
</Thead>
<Tbody>
<Tr>
<Td>api-gateway</Td>
<Td>europe-west</Td>
<Td textRight>42ms</Td>
</Tr>
<Tr>
<Td>auth</Td>
<Td>us-east</Td>
<Td textRight>88ms</Td>
</Tr>
</Tbody>
</Table>

Sizes

The size prop scales both text and cell padding, and it cascades from the table to every cell. Set it once on Table to size the whole table: xs, sm (default), md, lg, xl. The default has 14px text.

SizeValue
xs tabletightest
SizeValue
sm tabledefault
SizeValue
md tableroomy
SizeValue
lg tablespacious
SizeValue
xl tablewidest
<Stack>
<Table xs>
<Thead><Tr><Th scope="col">Size</Th><Th scope="col" textRight>Value</Th></Tr></Thead>
<Tbody><Tr><Td>xs table</Td><Td textRight>tightest</Td></Tr></Tbody>
</Table>
<Table>
<Thead><Tr><Th scope="col">Size</Th><Th scope="col" textRight>Value</Th></Tr></Thead>
<Tbody><Tr><Td>sm table</Td><Td textRight>default</Td></Tr></Tbody>
</Table>
<Table md>
<Thead><Tr><Th scope="col">Size</Th><Th scope="col" textRight>Value</Th></Tr></Thead>
<Tbody><Tr><Td>md table</Td><Td textRight>roomy</Td></Tr></Tbody>
</Table>
<Table lg>
<Thead><Tr><Th scope="col">Size</Th><Th scope="col" textRight>Value</Th></Tr></Thead>
<Tbody><Tr><Td>lg table</Td><Td textRight>spacious</Td></Tr></Tbody>
</Table>
<Table xl>
<Thead><Tr><Th scope="col">Size</Th><Th scope="col" textRight>Value</Th></Tr></Thead>
<Tbody><Tr><Td>xl table</Td><Td textRight>widest</Td></Tr></Tbody>
</Table>
</Stack>

Appearances and variants

An appearance on Table cascades to its rows and cells. outline (the default) colours the borders. filled fills the surface and draws the row lines in a translucent divider colour that reads on any fill. A cell with its own appearance, such as <Td danger>, keeps it. This needs @vaneui/ui 1.6.0 or later: before that, an appearance or variant on the Table did not reach the cells. The row lines of a filled Table need 1.6.2. An appearance without a variant on a Tr, Thead, Tbody or Tfoot, such as <Tr danger>, and a filled cell, such as <Td success filled>, need 1.7.2.

CheckResult
outline successborders take the colour
CheckResult
filled secondarysurface takes the colour
row linestranslucent on the fill
<Col>
<Table success>
<Thead><Tr><Th scope="col">Check</Th><Th scope="col" textRight>Result</Th></Tr></Thead>
<Tbody><Tr><Td>outline success</Td><Td textRight>borders take the colour</Td></Tr></Tbody>
</Table>
<Table filled secondary>
<Thead><Tr><Th scope="col">Check</Th><Th scope="col" textRight>Result</Th></Tr></Thead>
<Tbody>
<Tr><Td>filled secondary</Td><Td textRight>surface takes the colour</Td></Tr>
<Tr><Td>row lines</Td><Td textRight>translucent on the fill</Td></Tr>
</Tbody>
</Table>
</Col>

Striped and hoverable rows

striped tints every other body row, which helps the eye follow a wide row across the table. hoverable tints the row under the pointer. Both tints are a mix of the row's own text color, so they read on any appearance, in both color schemes, and a row or cell with its own fill keeps it. These props need @vaneui/ui 1.8.0 or later.

RegionLatency
Europe24ms
North America61ms
Asia Pacific142ms
South America118ms
<Table striped hoverable>
<Thead><Tr><Th scope="col">Region</Th><Th scope="col" textRight>Latency</Th></Tr></Thead>
<Tbody>
<Tr><Td>Europe</Td><Td textRight>24ms</Td></Tr>
<Tr><Td>North America</Td><Td textRight>61ms</Td></Tr>
<Tr><Td>Asia Pacific</Td><Td textRight>142ms</Td></Tr>
<Tr><Td>South America</Td><Td textRight>118ms</Td></Tr>
</Tbody>
</Table>

Per-cell and per-row size

A size on a Th, Td, or Tr overrides the table for that cell or row. Here an xs table keeps one xl cell and one lg row. An explicit md cell also holds md against a differently sized table.

Metricxl cell
tiny rowlarge
lg rowlg row
<Table xs>
<Thead><Tr><Th scope="col">Metric</Th><Th scope="col" xl textRight>xl cell</Th></Tr></Thead>
<Tbody>
<Tr><Td>tiny row</Td><Td xl textRight>large</Td></Tr>
<Tr lg><Td>lg row</Td><Td textRight>lg row</Td></Tr>
</Tbody>
</Table>

Column alignment

Set textLeft (default), textCenter, or textRight per cell. Right-align numeric columns so the digits line up.

PlanSeatsPrice
Starter3$0
Team25$99
Business100$499
<Table>
<Thead>
<Tr>
<Th scope="col">Plan</Th>
<Th scope="col" textCenter>Seats</Th>
<Th scope="col" textRight>Price</Th>
</Tr>
</Thead>
<Tbody>
<Tr><Td>Starter</Td><Td textCenter>3</Td><Td textRight>$0</Td></Tr>
<Tr><Td>Team</Td><Td textCenter>25</Td><Td textRight>$99</Td></Tr>
<Tr><Td>Business</Td><Td textCenter>100</Td><Td textRight>$499</Td></Tr>
</Tbody>
</Table>

A Text inside a right-aligned cell is its own fit-width box, so give it wFull textRight to line up with the column.

Trail Runner 2

$89.00

Merino socks (3 pairs)

$48.00

<Table>
<Tbody>
<Tr><Td>Trail Runner 2</Td><Td textRight><Text wFull textRight>$89.00</Text></Td></Tr>
<Tr><Td>Merino socks (3 pairs)</Td><Td textRight><Text wFull textRight>$48.00</Text></Td></Tr>
</Tbody>
</Table>

Text in a cell wraps between words, never inside one, so a name or a price stays whole in a narrow column.

Footer row

Add a Tfoot for totals or summary rows. Header cells (Th) carry the semibold treatment, so they read well for a total.

ItemAmount
Compute$120
Storage$30
Total$150
<Table>
<Thead>
<Tr><Th scope="col">Item</Th><Th scope="col" textRight>Amount</Th></Tr>
</Thead>
<Tbody>
<Tr><Td>Compute</Td><Td textRight>$120</Td></Tr>
<Tr><Td>Storage</Td><Td textRight>$30</Td></Tr>
</Tbody>
<Tfoot>
<Tr><Th scope="row">Total</Th><Th textRight>$150</Th></Tr>
</Tfoot>
</Table>

Caption

Caption renders a <caption> element that titles the table for screen readers. Its text follows the table size and accepts its own size to override.

Monthly active users by region
RegionUsers
Europe18,400
North America22,100
<Table>
<Caption>Monthly active users by region</Caption>
<Thead>
<Tr><Th scope="col">Region</Th><Th scope="col" textRight>Users</Th></Tr>
</Thead>
<Tbody>
<Tr><Td>Europe</Td><Td textRight>18,400</Td></Tr>
<Tr><Td>North America</Td><Td textRight>22,100</Td></Tr>
</Tbody>
</Table>

Outer border

Table has no border by default. Add border for an appearance-colored outer border. The table uses collapsed borders, so the corners stay square and there is no shape prop.

NameRole
AdaEngineer
GraceArchitect
<Table border>
<Thead><Tr><Th scope="col">Name</Th><Th scope="col">Role</Th></Tr></Thead>
<Tbody>
<Tr><Td>Ada</Td><Td>Engineer</Td></Tr>
<Tr><Td>Grace</Td><Td>Architect</Td></Tr>
</Tbody>
</Table>

Components in cells

Cells accept any VaneUI component. Drop a Badge into a status column.

ServiceRegionStatus
api-gatewayeurope-westHealthy
workerus-eastDegraded
schedulerus-eastDown
<Table>
<Thead>
<Tr><Th scope="col">Service</Th><Th scope="col">Region</Th><Th scope="col">Status</Th></Tr>
</Thead>
<Tbody>
<Tr>
<Td>api-gateway</Td>
<Td>europe-west</Td>
<Td><Badge success filled>Healthy</Badge></Td>
</Tr>
<Tr>
<Td>worker</Td>
<Td>us-east</Td>
<Td><Badge warning filled>Degraded</Badge></Td>
</Tr>
<Tr>
<Td>scheduler</Td>
<Td>us-east</Td>
<Td><Badge danger filled>Down</Badge></Td>
</Tr>
</Tbody>
</Table>

Font family

Cells render in the sans font (fontSans, the default), whatever font the page around them uses. Pass fontMono for machine output such as ids and hashes, or fontSerif / fontHeading.

CommitMessage
6aba224fix: make components consistent
899e2fdchore: release 1.4.3
<Table fontMono>
<Thead><Tr><Th scope="col">Commit</Th><Th scope="col">Message</Th></Tr></Thead>
<Tbody>
<Tr><Td>6aba224</Td><Td>fix: make components consistent</Td></Tr>
<Tr><Td>899e2fd</Td><Td>chore: release 1.4.3</Td></Tr>
</Tbody>
</Table>

Wide tables on small screens

A table never shrinks below its content. Wrap a wide one in <Col overflowXAuto relative> so it scrolls inside its own box instead of widening the page; relative keeps positioned children (a visually hidden header label, for example) inside the scroll box.

ServiceRegionOwnerp95 latency
api-gatewayeurope-westplatform-team42ms
<Col overflowXAuto relative>
<Table>
<Thead><Tr><Th scope="col">Service</Th><Th scope="col">Region</Th><Th scope="col">Owner</Th><Th scope="col" textRight>p95 latency</Th></Tr></Thead>
<Tbody><Tr><Td>api-gateway</Td><Td>europe-west</Td><Td>platform-team</Td><Td textRight>42ms</Td></Tr></Tbody>
</Table>
</Col>

Customizing

Set table defaults with ThemeProvider's themeDefaults. The table node has a slot for each part: main, thead, tbody, tfoot, tr, th, td, and caption.

Compact by default
Set the size once on the provider
<ThemeProvider themeDefaults={{
table: { main: { sm: true } },
}}>
<Table>
<Thead><Tr><Th scope="col">Compact by default</Th></Tr></Thead>
<Tbody><Tr><Td>Set the size once on the provider</Td></Tr></Tbody>
</Table>
</ThemeProvider>

Frequently asked questions

Can a Table sort or paginate its rows?

No: Table renders the markup and leaves the data to you. To sort, keep the rows in state, put a <Button type="button" ghost> in each sortable Th, and set aria-sort="ascending" or "descending" on the Th of the sorted column so screen readers announce the order. Render the pagination controls, such as a Row of Buttons, below the Table.

How do I make a whole table row a link?

A <tr> cannot be a link, so put a Link in the cell that names the row, usually the first one. That gives keyboard and screen reader users one focusable link per row. An onClick on the Tr adds a larger mouse target but no keyboard access, so keep the Link when you add one.

How do I highlight one row?

Give the Tr an appearance and a variant, such as <Tr filled info> or <Tr danger outline>. The cells of the row have no appearance of their own, so they follow the row as they follow the Table: filled paints the row background and switches its text and row rule to the fill. A cell with its own appearance, such as <Td danger>, keeps it.

Table Props

PropCategoryDefaultDescription
accent

Appearance

Accent color appearance (rose)

danger

Appearance

Danger color appearance (red)

info

Appearance

Info color appearance (cyan)

inheritAppearance

Appearance

Inherit appearance from parent — suppresses own data-appearance/data-variant, uses parent's CSS variables

primary

Appearance

Primary color appearance (gray)

secondary

Appearance

✓

Secondary color appearance (gray)

success

Appearance

Success color appearance (green)

tertiary

Appearance

Tertiary color appearance

warning

Appearance

Warning color appearance (amber)

fontHeading

Font Family

Heading font family (defaults to sans, customizable via --font-heading) — emits font-heading

fontMono

Font Family

Monospace font family — emits font-mono

fontSans

Font Family

✓

Sans-serif font family (default) — emits font-sans

fontSerif

Font Family

Serif font family — emits font-serif

hoverable

Hoverable

The body row under the pointer takes a hover background

margin

Margin

Enable margin on all sides

marginB

Margin

Enable only bottom margin

marginT

Margin

Enable only top margin

marginX

Margin

Enable only horizontal (inline) margin

marginY

Margin

Enable only vertical (block) margin

noMargin

Margin

Disable margin (reset to 0)

lg

Size

Large size

md

Size

Medium size (default)

sm

Size

✓

Small size

xl

Size

Extra large size

xs

Size

Extra small size

skeleton

Skeleton

Show the component as a loading placeholder in its own size and shape. On a container, every component inside it becomes a placeholder too

striped

Striped

Body rows on alternating backgrounds

textCenter

Text Align

Align text to center

textEnd

Text Align

Align text to the reading-direction end (right in LTR, left in RTL)

textJustify

Text Align

Justify text

textLeft

Text Align

Align text to left (physical side, does not flip under RTL)

textRight

Text Align

Align text to right (physical side, does not flip under RTL)

textStart

Text Align

Align text to the reading-direction start (left in LTR, right in RTL)

filled

Variant

Filled variant - solid background with contrasting text color

ghost

Variant

Ghost variant - transparent background, no border, appearance-colored text, tinted hover background

outline

Variant

✓

Outline variant - transparent background with border and colored text (default)

Layout & utility props (gap, padding, hide, items, justify, ...)

Documented on Common Props.

PropCategoryDefaultDescription
border

Border

Enable border on all sides

borderB

Border

Enable border on bottom

borderEnd

Border

Enable border on the inline-end side (right in LTR, left in RTL)

borderL

Border

Enable border on left

borderR

Border

Enable border on right

borderStart

Border

Enable border on the inline-start side (left in LTR, right in RTL)

borderT

Border

Enable border on top

borderX

Border

Enable border on left and right

borderY

Border

Enable border on top and bottom

noBorder

Border

✓

Disable all borders

desktopHide

Hide

Hide element on desktop devices and below (max-desktop: 80rem)

mobileHide

Hide

Hide element on mobile devices and below (max-mobile: 48rem)

tabletHide

Hide

Hide element on tablet devices and below (max-tablet: 64rem)

responsiveSizing

Responsive Sizing

Enable responsive sizing - uses breakpoint-specific classes for font size, padding, and gap

desktopWFull

Responsive Width

Set width to 100% on desktop and below, below 1280px (max-desktop: 80rem)

mobileWFull

Responsive Width

Set width to 100% on mobile, below 768px (max-mobile: 48rem)

tabletWFull

Responsive Width

Set width to 100% on tablet and below, below 1024px (max-tablet: 64rem)

desktopShow

Show

Show element only on desktop and below, below 1280px (hidden from 80rem up)

mobileShow

Show

Show element only on mobile, below 768px (hidden from 48rem up)

tabletShow

Show

Show element only on tablet and below, below 1024px (hidden from 64rem up)

wAuto

Width

Set width to auto

wFit

Width

Set width to fit-content

wFull

Width

✓

Set width to 100%

wScreen

Width

Set width to 100vw (viewport width), removes max-width constraint