Skip to content
Block Kit for React
Esc
↑↓navigate↵open⌘Jpreview
On this page

Theming

Light and dark mode, the --sbk-* CSS custom properties, fonts, and isolation from your app's global styles.

Every color in the stylesheet is a --sbk-* CSS custom property, measured from Slack’s own Block Kit Builder. Dark mode is a matter of which values are active. You rarely need to override them, but they’re there when you do.

Your AppAPP
Matches Slack in light and dark.

Light and dark mode

By default, dark values apply under prefers-color-scheme: dark: the page follows the visitor’s OS setting, same as Slack’s own desktop client.

To force a theme regardless of OS preference, set data-theme on <html> (or any ancestor of your Block Kit content):

<html data-theme="dark"></html>
<html data-theme="light"></html>

data-theme="light" also works as an escape hatch to opt an element back out of dark mode even when the OS prefers it.

data-theme also sets the element’s color-scheme, as Slack does, so text selections, native scrollbars and the caret are drawn for that theme. Without data-theme the package leaves color-scheme to your page.

The theme prop

<BlockKitProvider theme="light" | "dark"> sets data-theme on a wrapper <div> around its children, and on the menus, tooltips and dialogs it opens outside that wrapper. It’s useful for previewing both themes side by side on the same page, independent of the OS setting:

<div style={{ display: "flex", gap: 16 }}>
  <BlockKitProvider theme="light">
    <Message blocks={blocks} />
  </BlockKitProvider>
  <BlockKitProvider theme="dark">
    <Message blocks={blocks} />
  </BlockKitProvider>
</div>

Leave theme unset to follow the page’s own data-theme/prefers-color-scheme instead.

Slack’s other dark themes

Slack offers several dark themes; the dark values follow its default one. Callout backgrounds and area chart fills in dark mode are derived from that palette rather than measured. To match another theme, override the tokens under [data-theme="dark"]:

[data-theme="dark"] {
  --sbk-callout-green-bg: #1f3a2c;
  --sbk-chart-area-1: #5c3320;
}

CSS custom properties

The full set lives in base.css and Message.css. Override any of them after importing the stylesheet to restyle without touching the components. The main tokens:

PropType
--sbk-font?string

Body font. See Fonts below.

Typestring
Default"Slack-Lato", Lato, sans-serif
--sbk-font-mono?string

Code font.

Typestring
Default"Slack-Roboto-Mono", "Roboto Mono", monospace
--sbk-text?color

Primary text color: cards, charts, data tables, container titles, alerts and controls.

Typecolor
--sbk-text-body?color

The text messages and blocks inherit (section, rich text, mrkdwn, sender name, input labels), and a confirmation dialog's title and text. Same as --sbk-text in light; a little softer in dark, as in Slack.

Typecolor
--sbk-text-sec?color

Secondary text: the timestamp, context, image titles and card subtext.

Typecolor
--sbk-muted?color

Muted text, e.g. the (edited) marker and a text input's icon.

Typecolor
--sbk-content-ter?color

Tertiary text: field placeholders, input hints, the (optional) label and card subtitles.

Typecolor
--sbk-broadcast-text?color

The text of @here, @channel and @everyone mentions.

Typecolor
--sbk-tag-bg?color

A rich text tag label's background; --sbk-tag-text is its text.

Typecolor
--sbk-video-byline?color

A video's author name, below its title.

Typecolor
--sbk-video-provider?color

A video's provider name, before the author.

Typecolor
--sbk-video-separator?color

The | between a video's provider and author; defaults to --sbk-video-byline.

Typecolor
--sbk-block-error-text?color

"This content could not be displayed.", drawn at half opacity.

Typecolor
--sbk-bg?color

Surface background (message, modal, Home tab).

Typecolor
--sbk-link?color

Link and mention text color.

Typecolor
--sbk-mention-bg?color

Resolved user/channel mention background.

Typecolor
--sbk-chip-bg?color

A multi-select's chosen-option chip background.

Typecolor
--sbk-primary?color

Primary button background (e.g. modal Submit).

Typecolor
--sbk-danger?color

Danger-styled button background.

Typecolor
--sbk-primary-hover-tint?color

The tint over a hovered primary button, blended as Slack does: darkening in light, lightening in dark. --sbk-primary-pressed-tint, --sbk-danger-hover-tint and --sbk-danger-pressed-tint do the same for a pressed primary button and a danger button.

Typecolor
--sbk-border?color

Default hairline border color.

Typecolor
--sbk-divider?color

Divider block color.

Typecolor
--sbk-code-text?color

Inline code text.

Typecolor
--sbk-code-bg?color

Inline code and rich text preformatted block background.

Typecolor
--sbk-pre-text?color

Rich text preformatted block text.

Typecolor
--sbk-code-block-bg?color

The Markdown block's fenced code box background.

Typecolor
--sbk-focus-ring?color

Keyboard focus ring and focused input border.

Typecolor
--sbk-menu-bg?color

Calendar and other popover background.

Typecolor
--sbk-c-menu-bg?color

Overflow and data table sort menu background (Slack's c-menu).

Typecolor
--sbk-surface-sec?color

Secondary surface: select and time lists.

Typecolor
--sbk-select-border?color

Border of select, text, date and time fields.

Typecolor
--sbk-calendar-today?color

Today's number and ring in the date picker calendar.

Typecolor
--sbk-tooltip-bg?color

Tooltip background.

Typecolor
--sbk-callout-green-bg?color

Callout background, one per background_color: green, blue, red, yellow, purple, gray.

Typecolor
--sbk-chart-1?color

Chart series and segment color, --sbk-chart-1 to -12; Slack's dark charts use a deeper set.

Typecolor
--sbk-chart-1-lift?color

The color a chart mark lifts to under the pointer, one per series color: --sbk-chart-1-lift to -12-lift.

Typecolor
--sbk-chart-area-1?color

Area chart fill, one per series color: --sbk-chart-area-1 to -12.

Typecolor
--sbk-chart-tooltip-bg?color

Chart hover tooltip background; --sbk-chart-tooltip-text is its text.

Typecolor
:root {
  --sbk-primary: #1264a3;
  --sbk-primary-hover: #0b4c80;
}

Fonts

Slack sets body text in Lato and code in Roboto Mono, but Slack’s own font files aren’t redistributable. Install the open-source builds from Fontsource instead:

npm install @fontsource/lato @fontsource/roboto-mono
pnpm add @fontsource/lato @fontsource/roboto-mono
yarn add @fontsource/lato @fontsource/roboto-mono
bun add @fontsource/lato @fontsource/roboto-mono
nub add @fontsource/lato @fontsource/roboto-mono
aube add @fontsource/lato @fontsource/roboto-mono
import "@fontsource/lato/400.css";
import "@fontsource/lato/400-italic.css";
import "@fontsource/lato/700.css";
import "@fontsource/lato/900.css";
import "@fontsource/roboto-mono/400.css";

The stylesheet asks for Slack-Lato first, then falls back to plain Lato, so if you’re already serving Lato yourself (a CDN, self-hosted @font-face), you can skip installing Fontsource: any font-family: Lato declaration is picked up.

Field text on phones

Text fields use Slack’s sizes: 13px, or 15px for multiline and rich text inputs. iOS Safari zooms the page in whenever a field with text under 16px takes focus, so on a touch-only screen ((hover: none) and (pointer: coarse)) every text field takes 16px text in the same box. A desktop keeps Slack’s sizes, even with a touchscreen, and pinch zoom keeps working everywhere.

Isolation from your app’s global CSS

Every component’s root carries an sbk-root class (portalled dialogs and tooltips get it too), and the stylesheet rolls everything under it back to the browser’s defaults before applying its own rules:

:is(.sbk-root, .sbk-confirm__overlay, .sbk-tooltip)
  :where(:not(svg, svg *, img, video, canvas, iframe, embed, object)) {
  all: revert;
}

This means global resets in your app (Tailwind’s preflight, a docs theme’s heading font, a blanket * { min-width: 0 }) don’t leak into how a block renders, and the reverse: block styles don’t leak into your app either, since everything is scoped under .sbk-root. You don’t need to configure anything for this; it’s automatic once you import @nkootstra/block-kit/styles.css.

Touch screens, reduced motion and high contrast

The styles adapt to the device and the user’s settings, without changing how a message looks on a desktop:

  • Hover styles apply only where the pointer can hover precisely (a mouse or trackpad), so a tap on a touch screen doesn’t leave a control looking hovered. Code blocks’ copy button and the hover actions on images and charts still appear on a tap, since that’s the only way to reach them there.
  • Reduced motion: with the system setting on, nothing slides or scales. The collapsible blocks and containers open at once, dialogs and modals appear without their entrance, and the carousel’s arrows only fade. The loading spinner keeps turning, more slowly.
  • High contrast (forced colours, such as Windows’ contrast themes): focus rings drawn with a shadow disappear there, so focused links, mentions, fields and buttons also carry a transparent outline, which the system paints in its own colour.

Last updated on