Skip to Content
CodeUI

Table

@codeui/solid v0.3.0

Style native HTML tables with Inkstone.

When to use

Use Table to present data in rows and columns. Add a caption to name the table and use header cells to identify rows or columns.

Live demo

Export formats
FormatUseScale
PNGHigh-resolution screenshots2×
JPEGSmaller files for sharing1×
SVGScalable artworkAny
table/basic.tsx
import { Table, TableScrollArea, type TableProps } from "@codeui/solid";

export default function ExportFormats(props: Pick<TableProps, "size" | "striped">) {
	return (
		<TableScrollArea aria-label="Export formats">
			<Table size={props.size} striped={props.striped}>
				<caption>Export formats</caption>
				<thead>
					<tr>
						<th scope="col">Format</th>
						<th scope="col">Use</th>
						<th scope="col" style={{ "text-align": "end" }}>
							Scale
						</th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<th scope="row">PNG</th>
						<td>High-resolution screenshots</td>
						<td style={{ "text-align": "end" }}>2×</td>
					</tr>
					<tr>
						<th scope="row">JPEG</th>
						<td>Smaller files for sharing</td>
						<td style={{ "text-align": "end" }}>1×</td>
					</tr>
					<tr>
						<th scope="row">SVG</th>
						<td>Scalable artwork</td>
						<td style={{ "text-align": "end" }}>Any</td>
					</tr>
				</tbody>
			</Table>
		</TableScrollArea>
	);
}

Anatomy

Export formats
FormatUseScale
PNGHigh-resolution screenshots2×
JPEGSmaller files for sharing1×
SVGScalable artworkAny

Tap a part to outline it in the demo.

  1. 01Tabletableclasses.root
  2. 02TableScrollAreatable-scroll-areaclasses.scrollArea
ExportRendersclasses keydata-cuiRole
TabletableroottableTable
TableScrollAreadivscrollAreatable-scroll-areaRegion when named

Use native caption, thead, tbody, tfoot, tr, th, and td inside Table. The table stylesheet applies to these elements.

Variants

Size

Export formats
FormatUseScale
PNGHigh-resolution screenshots2×
JPEGSmaller files for sharing1×
SVGScalable artworkAny
table/compact.tsx
import ExportFormats from "./basic";

export default function CompactTable() {
	return <ExportFormats size="sm" />;
}

size="sm" reduces cell padding. Use the default md when you have room for more space between rows.

Striped rows

Export formats
FormatUseScale
PNGHigh-resolution screenshots2×
JPEGSmaller files for sharing1×
SVGScalable artworkAny
table/striped.tsx
import ExportFormats from "./basic";

export default function StripedTable() {
	return <ExportFormats striped />;
}

Set striped to give alternating body rows a neutral fill.

Ready API

Import Table and TableScrollArea from @codeui/solid or @codeui/solid/table.

Table

Pass native table attributes such as id and aria-describedby to Table. Use class or classes.root to extend the table styles. Add classes directly to cells for column-specific styles.

PropTypeDefault
size"sm" | "md""md"
stripedbooleanfalse

TableScrollArea

Wrap Table in TableScrollArea when the columns may exceed the available width. Give the scroll area a name with aria-label or aria-labelledby, so keyboard users can identify it. Use class or classes.scrollArea to extend the scroll area styles.

Styles export

tableStyles

Load @codeui/styles/theme.css and @codeui/styles/table.css when you use the styles outside Solid. Import tableStyles from @codeui/styles/table. Apply tableStyles.root() to a native table and tableStyles.scrollArea() to its scroll container.

Set data-size="sm" for compact cells and data-striped="true" for alternating row fills. The Markdown table in Ready API uses the same stylesheet.

Accessibility

Add scope="col" to column headers and scope="row" to row headers. Use a caption when the table needs a visible name. Keep interactive content in native controls so it stays in the page's tab order.

SSR notes

Table and TableScrollArea render their native HTML, classes, and attributes on the server.

On this page