SpreadsheetGrid
Guides

Theming and styling

Dark themes (light / dark / auto / class), density, and customization with CSS tokens

There are 3 levels of customizing the look: ① switching presets with the theme / density props, ② overriding tokens with CSS custom properties (--ssg-*), and ③ class hooks such as className / classNames / cellClassName. ③ all accept string | { className, style }, so you can pass the return value of StyleX's stylex.props() as is (see below).

Demo

Rows 5 of 5Columns 3 of 3Sort: —
#
1
2
3
4
5
Rows 5 of 5Columns 3 of 3
Cell —Range —0 cells / 0 rows0 columns

Themes (dark mode)

<SpreadsheetGrid theme="class" ... />  // 'light' (default) | 'dark' | 'auto' | 'class'
  • 'auto' follows the OS / browser prefers-color-scheme. With SSR, it first renders light and follows after hydration.
  • 'class' turns dark by looking at an ancestor's class="dark" or data-theme="dark" in CSS. It's for pages that switch dark mode with <html class="dark">, like Tailwind CSS / next-themes / shadcn/ui / HeroUI, and has the right colors from the server render (no white table flashing on a dark page). Switching follows with CSS alone too.
    • Popups such as menus and tooltips appear directly under document.body, so put the dark class (or data-theme="dark") on <html> or <body> (the next-themes default).
    • Pass the same theme="class" to GridAskBar too.
  • For things that decide dark mode with something other than a class or data-theme, like Mantine (data-mantine-color-scheme), pass the resolved value of your color scheme hook as 'light' | 'dark' (to match a design system's colors, see also design system themes).
  • The theme applies not only to the grid itself but to popovers, menus, panels, tooltips and drag ghosts all at once.

Density

<SpreadsheetGrid density="compact" ... />  // 'standard' (default) | 'compact' | 'comfortable'

Row height (36 / 28 / 44px for standard / compact / comfortable; header rows 40 / 32 / 48px), cell padding, icon sizes and relative text sizes switch together. Explicit rowHeight / headerHeight win over the preset.

Customizing with CSS tokens

Design tokens are defined with zero specificity (:where(.ssg-root)), so a single ordinary class reliably overrides them.

.my-grid {
  --ssg-accent: #7c3aed;          /* accent (selection outline and so on) */
  --ssg-header-bg: #f8fafc;       /* header background */
  --ssg-invalid: #dc2626;         /* color for failed validation */
  --ssg-note-indicator: #f59e0b;  /* cell note (cellNote) mark */
  --ssg-cf-bar: rgba(124, 58, 237, 0.26); /* conditional formatting data bar. The default is a fixed blue that doesn't follow the accent (also --ssg-cf-seq-* / --ssg-cf-div-* / --ssg-cf-good and so on) */
  --ssg-tooltip-bg: #1e293b;      /* tooltip background */
}
<SpreadsheetGrid className="my-grid" ... />

The column menu, column filters, context menu, select options, tool panel, tooltips and drag ghosts appear directly under document.body, so they don't inherit from the table. When they open, the grid copies the token values resolved on the table's root to them, so tokens written for the table as above (className / .ssg-root { … } / ancestor selectors like .card .ssg-root { … } / values using ancestor variables) show in the same colors in popups too.

  • To use different values only in popups, write them in the style of classNames.popover / classNames.tooltip, or on popup classes like .ssg-menu-panel / .ssg-tooltip. Values set on the popup's side win over copied values (a value written in CSS that equals the default can't be told apart, so to keep the default color, write it with style).
  • Density (density) sizes don't apply to popups (as before).
  • When attributes of <html> / <body> (dark mode classes and so on) or the OS color scheme change while open, the values are copied again. When you replace your CSS in other ways, it catches up the next time they open.
  • The approach recommended in earlier versions, passing the same class to popover / tooltip / dragGhost of classNames too, still works.

Raising contrast

Among the default colors, secondary text in panels (filter counts, empty states like "No sorting", section headings in the column chooser, unselected tabs in the tool panel) doesn't reach WCAG AA's 4.5:1 (2.56:1 / 4.27:1 on white). To meet accessibility standards, override with these values (changing the default colors would change the look, so the defaults stay).

.my-grid {
  --ssg-panel-text-muted: #475569;  /* tool panel tabs and so on (6.8:1) */
  --ssg-panel-text-faint: #64748b;  /* counts, empty states, section headings (4.8:1) */
}
.my-grid.ssg-theme-dark {
  --ssg-panel-text-faint: #909296;  /* counts, empty states, section headings in dark (4.8:1) */
}

With theme="class", write it with the ancestor selector that decides dark mode, like .dark .my-grid.

The text of conditional formatting chips has a contrast of 5:1 or more against its background for all 5 tones since 1.3.0 (good / warning / critical were darkened). To go back to the colors up to 1.2, write --ssg-cf-good: #15803d; --ssg-cf-warning: #b45309; --ssg-cf-critical: #dc2626;.

High contrast (forced-colors)

In environments where the browser replaces colors with system colors, such as Windows high contrast (@media (forced-colors: active)), token colors are mostly unused. Parts where the color itself carries meaning are drawn like this (since 1.0.2).

  • Cells failing validation: instead of a pink background, a dotted outline in the highlight color (Highlight) inside the cell. The top-right mark is a triangle in the highlight color, and the note mark is a triangle in the text color.
  • Unsaved marks of change tracking (trackChanges): the triangle in the cell's top left and the dot on the row number are drawn in the highlight color (Highlight) (since 1.8.0). The vertical line to the left of the row number of rows added with trackChanges={{ rows: true }} is the same highlight color (since 1.10.0).
  • Entry row (newRow): the text of an empty entry row is GrayText (to tell it apart from typed values), and the row number marks (* / ✎) are shown as text (since 1.10.0).
  • Conditional formatting chips (conditionalFormat.chips) and data bars: drawn in the specified colors without replacement, and chips get an outline in the text color (so states can be told apart even in columns with icon: false).

Theme builder

In the theme builder, pick one brand color and it makes the light and dark palettes at once, with a real grid in each side by side. Copy the generated CSS variables and paste them.

  • The brand color reaches the active cell border, range selection, selected rows, checkboxes, selected items in panels, data bars and color scales, info chips and the current find match. "How much brand color" (Subtle / Standard / Bold) sets how much it also tints headers and bands such as group and total rows.
  • "Gray tint" moves the grays of surfaces, borders and muted text toward the brand hue (0 keeps them neutral).
  • In dark, the brand color is lightened so it stays visible on dark surfaces. The CSS has a light block and a dark block; the dark block applies to theme="dark" / "auto" and to theme="class" under .dark or [data-theme="dark"].
  • Hard-to-read pairs (below the WCAG contrast ratio of 4.5:1 for text or 3:1 for borders and icons) are fixed by moving only their lightness, keeping hue and vividness, and the fixes are listed. The overrides in "Raising contrast" above are not needed.
  • Meaningful colors (input errors, saved marks, diffs, and good / warning / critical chips) keep the library defaults instead of following the brand. You are told when the brand color is close to one of them.
  • Under "Details" you can set the cell background, text, header background, grid lines and border for light and dark separately. You can also start from presets (Default / Mantine-like / HeroUI-like / Business gray / Excel-like), and the state goes in the URL so you can share it with your team.

Conditional cell styles

{
  key: 'qty', title: 'Qty', width: 110,
  cellClassName: ({ value }) =>
    typeof value === 'number' && value < 10 ? 'my-warn-cell' : undefined,
}
/* chain onto the base class to win on specificity (independent of import order) */
.ssg-body-cell.my-warn-cell {
  background-color: #fff7ed;
}

To combine with states like row hover or read-only, chain with the public state classes (.ssg-body-cell--row-hovered / .ssg-body-cell--readonly and so on). For the list, see "State classes for styling" in the SpreadsheetGrid props.

Part slots (classNames) and the { className, style } form

classNames is a table of slots for adding classes per part (root / toolbar / statusBar / headerRow / headerCell / rowHeaderCell / cornerCell / bodyRow / bodyCell / groupRow / groupCell / detailBand / detailCard / iconButton / popover / menuItem / tooltip / dragGhost / checkbox / cellEditor / emptyState / filterChipBar / errorBar / scrollHint / activeCellOverlay / selectionOverlay; where each goes is listed in the props reference).

Values of classNames.* / cellClassName / getRowClassName / detailRow.className are GridSlotProps = string | { className?: string; style?: CSSProperties }. A string is a class as before, and the object form adds style inline on that element besides the class (the Solid version has the same shape, still named className; style uses Solid's syntax = 'font-style': 'italic'). The root element also accepts the style prop.

<SpreadsheetGrid
  style={{ maxWidth: 960 }}
  classNames={{
    root: 'my-grid',                                       // string
    bodyCell: { className: 'tabular', style: { fontVariantNumeric: 'tabular-nums' } },
    popover: { style: { '--ssg-accent': '#7c3aed' } },     // a different value only for popups (directly under body)
  }}
  getRowClassName={(row) => (row.archived ? { className: 'is-archived', style: { fontStyle: 'italic' } } : undefined)}
/>
/* to dim a row, chain onto the row class (applies once, to the row only) */
.ssg-body-row.is-archived {
  opacity: 0.5;
}
  • Coordinates and sizes the grid uses for positioning (left / top / width / height / transform and so on) are overwritten by the grid last, so a slot's style can't break the layout.
  • Set the grid's height with the height prop, not style (the root's style={{ height }} alone doesn't set the scroll area's height, and the bars may be cut off). For details, see Sizing (height).
  • Inline styles win over state classes too (backgrounds for selection, hover and so on). Do decoration that should switch with state on the className side.
  • The class and style from getRowClassName go on the row (.ssg-body-row), the "#" cell and every cell. Returning settings that get stronger when stacked, like opacity / filter, as style, or writing them with a class alone like .is-archived { opacity: 0.5 }, applies them twice (row and each cell) for 0.25. Apply them to the row only with .ssg-body-row.is-archived, as in the example above. Background colors are held by cells, so write them on .ssg-body-cell.is-archived.
  • You may pass a new classNames object on every render (it's memoized by a signature of its contents, so row and header re-renders don't increase).
  • tooltip / dragGhost are imperative DOM, so numbers in their style get no units (write strings like '12px').

Using it with StyleX

StyleX (@stylexjs/stylex) works together as is. It has no reset, and its generated classes are prefixed with x, so they don't clash with the base CSS. stylex.props(...) returns { className, style }, so you can pass it to the slots above as is (StyleX's dynamic styles arrive as CSS variables on the style side, so this form is needed).

import * as stylex from '@stylexjs/stylex';
import { vars } from './tokens.stylex';   // stylex.defineVars({ accent: '#7c3aed', danger: '#dc2626' })

const s = stylex.create({
  grid: { '--ssg-accent': vars.accent, borderRadius: 8 },   // bridge to the grid's tokens
  cell: { fontVariantNumeric: 'tabular-nums' },
  negative: { color: vars.danger },
  width: (w: number) => ({ maxWidth: w }),                  // dynamic style
});

<SpreadsheetGrid
  classNames={{ root: stylex.props(s.grid), bodyCell: stylex.props(s.cell) }}
  columns={[
    {
      key: 'amount',
      title: 'Amount',
      cellClassName: (ctx) => stylex.props(typeof ctx.value === 'number' && ctx.value < 0 && s.negative, s.width(120)),
    },
  ]}
/>
  • StyleX can't write descendant selectors (it can only decorate elements with their own classes), so adjust internal elements without slots (buttons and inputs in popovers and so on) with CSS tokens (--ssg-*).
  • StyleX's atomic classes and the grid's base classes have the same specificity (0,1,0). When both set the same property, the one loaded later wins, so load the grid CSS first and StyleX's output CSS after, or use style.layer.css (which puts the whole grid in @layer ssg-base). If you enable useLayers in StyleX, the unlayered grid CSS always wins, so style.layer.css is required.

For use inside Astryx, the design system built with StyleX, there's themes/astryx.css, which matches the colors to the Astryx theme (Mantine / HeroUI / shadcn/ui have the same kind; Matching a design system).

For coexistence with Tailwind (layer setup, style.layer.css), see Loading the CSS and coexistence.

On this page