---
title: Theme the chat
description: "Restyle <AgentChat> without a fork: CSS variables, a theme object or JSON, or your own component for one part. Light and dark, unstyled, and every token with its default."
related:
  - /build/style-the-cursor-and-chat
  - /more/chat-localization
  - /testing/test-the-chat
---

Every visual value of `<AgentChat>` is a `--wa-chat-*` CSS variable, and every element it renders carries a
`data-wa-part` attribute. That gives you three levels of control, from one line of CSS to your own component, with no
fork and no `!important`. Start at the first level and go further only when it is not enough.

[Style the cursor and the chat](/docs/build/style-the-cursor-and-chat) covers the common case (your brand color, in light
and dark). This page is the rest.

## Level 1: CSS variables

Set the variables anywhere above the chat; `:root` works. The chat reads each one at its root and falls back to its
default, so the value you set wins without any specificity games.

```css title="chat.css"
/* Level 1: variables only. Set them anywhere above the chat. */
:root {
  --wa-chat-color-accent: oklch(0.62 0.19 255);
  --wa-chat-color-user-bubble: var(--wa-chat-color-accent);
  --wa-chat-radius-panel: 20px;
  --wa-chat-radius-bubble: 14px;
  --wa-chat-font-family: "Inter", system-ui, sans-serif;
  --wa-chat-size-width: 420px;
}

/* One part, in one state: every element has data-wa-part. */
[data-wa-part="toolCard"][data-state="awaiting-confirmation"] {
  border-style: dashed;
}
```

To style one element, select its part, and its state where it has one (`data-state`, `data-role`, `data-open`,
`data-busy`). The parts are listed on [Chat parts](/docs/reference/chat/chat-parts).

A variable set here applies in light and in dark. To give dark its own value, use the condition the chat uses for
dark (`prefers-color-scheme: dark`, or `data-theme="dark"` on the chat or an ancestor), or use a theme object with
`light` and `dark` (next section), which writes that condition for you.

## Level 2: a theme object, or JSON

`theme` takes the same variables as data: each key is one variable (`color.accentInk` is
`--wa-chat-color-accent-ink`). Pass one theme, or one per scheme:

```ts title="theme.ts"
import { defineChatTheme } from "@webmcp-agents/chat";

// Level 2: the same variables as data. One theme for both schemes,
// or one per scheme, as here.
export const theme = defineChatTheme({
  light: {
    color: { accent: "#0f62fe", bg: "#ffffff", fg: "#161616" },
    radius: { panel: "16px" },
  },
  dark: {
    color: { accent: "#78a9ff", bg: "#161616", fg: "#f4f4f4" },
  },
});
```

```tsx title="chat.tsx"
import { AgentChat } from "@webmcp-agents/chat";

import { shopper } from "@/agents";
import { messages } from "./messages";
import { theme } from "./theme";

// Declared once, outside the render: the same objects every time.
export function Chat() {
  return (
    <AgentChat
      agent={shopper}
      theme={theme}
      messages={messages}
      classNames={{ panel: "shadow-2xl" }}
      styles={{ launcher: { insetInlineEnd: 24 } }}
    />
  );
}
```

`classNames` adds your classes to a part, and `styles` sets inline styles on it: the way to use Tailwind or your own
design system on single elements.

Because a theme is plain data, it can come from a JSON file or a CMS, with the words and the locale beside it:

```json title="chat-config.json"
{
  "locale": "ar",
  "theme": {
    "color": { "accent": "#0a7d5a" },
    "font": { "family": "IBM Plex Sans Arabic, system-ui" }
  },
  "messages": {
    "title": "مساعد المتجر",
    "composer": { "placeholder": "اكتب رسالتك…" },
    "steps": "{count, plural, one {خطوة واحدة} two {خطوتان} few {# خطوات} other {# خطوة}}"
  }
}
```

```tsx title="chat.tsx"
import { AgentChat, type ChatCustomization } from "@webmcp-agents/chat";

import { shopper } from "@/agents";
import config from "./chat-config.json";

// Plain JSON (a file, a CMS, a fetch): the theme, the words and
// the locale are all data.
const custom: ChatCustomization = config;

export function Chat() {
  return <AgentChat agent={shopper} {...custom} />;
}
```

A key that is not a token is ignored, and a value containing `;`, `{`, `}` or `!` is dropped, so a theme from outside
your code cannot inject other CSS.

### Light, dark and your own switch

By default the chat follows the system setting, and `data-theme="dark"` on any ancestor forces dark (so a site whose
theme switch writes `data-theme` on `<html>` needs nothing). `colorScheme` forces one scheme from React:

```tsx title="chat.tsx"
import { AgentChat } from "@webmcp-agents/chat";

import { shopper } from "@/agents";
import { theme } from "./theme";

// Your site's own switch decides: "light" or "dark" always win
// over the system setting. "auto" (the default) follows it.
export function Chat({ dark }: { dark: boolean }) {
  return (
    <AgentChat
      agent={shopper}
      theme={theme}
      colorScheme={dark ? "dark" : "light"}
    />
  );
}
```

`"light"` and `"dark"` always win, over the system and over an ancestor. `"auto"` is the default.

### A page without React

`themeToCssVars` turns a theme into the variables, for a server render that should not flash or a page that mounts
the chat some other way:

```ts title="theme.ts"
import { themeToCssVars } from "@webmcp-agents/chat";

// A page without React, or a server render that should not flash:
// the theme as CSS variables, on any element above the chat.
const vars = themeToCssVars({ color: { accent: "#e11d48" } });
for (const [name, value] of Object.entries(vars)) {
  document.documentElement.style.setProperty(name, value);
}
```

## Level 3: replace a part

`components` takes your own component for any of the replaceable parts: `Launcher`, `Header`, `Message`, `Text`,
`ToolCard`, `Reasoning`, `Suggestions`, `Composer`, `DownloadCard`, `ModelPicker`, `Empty`, `Error`, `Icon` and
`Restore`. Each receives `partProps` (spread them on your root element to keep the part's attribute, classes and
styles), the merged `messages`, the translate function `t`, and the part's own data.

```tsx title="chat.tsx"
import { AgentChat, type ChatComponents } from "@webmcp-agents/chat";

import { shopper } from "@/agents";

// Level 3: your own component for one part. Spread partProps on its
// root: it keeps data-wa-part, your classNames and styles.
const ToolCard: ChatComponents["ToolCard"] = ({
  partProps,
  call,
  t,
}) => (
  <div {...partProps} data-state={call.state}>
    <strong>{call.tool}</strong>{" "}
    <span>{t("tool.running", { tool: call.tool })}</span>
  </div>
);

export function Chat() {
  return <AgentChat agent={shopper} components={{ ToolCard }} />;
}
```

Define the component outside the one that renders the chat, so React does not see a new component on every render.
Every prop is on [`ChatComponents`](/docs/reference/chat/chat-components).

### No library CSS at all

`unstyled` renders the same markup with no class and no variable: only the `data-wa-part` attributes and your own
classes. Do not import `@webmcp-agents/chat/chat.css` then.

```tsx title="chat.tsx"
import { AgentChat } from "@webmcp-agents/chat";

import { shopper } from "@/agents";

// No chat.css import: only data-wa-part hooks and your classes.
export function Chat() {
  return (
    <AgentChat
      agent={shopper}
      unstyled
      classNames={{
        panel: "rounded-xl border bg-background",
        send: "btn btn-primary",
      }}
    />
  );
}
```

## Every token

The table is generated from `chat.css`. "Follows" means the token takes another token's value unless you set it. In
dark, where the browser supports relative colors, the accent is a light tint of the cursor's `--agent` color instead
of the value shown.

{/* Generated by apps/docs/scripts/generate-partials.mjs from the code: do not edit by hand. */}

| Variable | Default | Dark default | 0.4.0 name |
|---|---|---|---|
| `--wa-chat-color-bg` | `#ffffff` | `#1c1c1f` | `--wa-chat-bg` |
| `--wa-chat-color-fg` | `#111111` | `#f2f2f3` | `--wa-chat-fg` |
| `--wa-chat-color-muted` | `#5f6368` | `#a1a1aa` | `--wa-chat-muted` |
| `--wa-chat-color-soft` | `rgba(17, 17, 17, 0.05)` | `rgba(255, 255, 255, 0.07)` | `--wa-chat-soft` |
| `--wa-chat-color-line` | `rgba(17, 17, 17, 0.1)` | `rgba(255, 255, 255, 0.12)` | `--wa-chat-line` |
| `--wa-chat-color-accent` | `var(--agent, #111111)` | `var(--wa-chat-fg)` | `--wa-chat-accent` |
| `--wa-chat-color-accent-ink` | `var(--agent-ink, #ffffff)` | `var(--wa-chat-bg)` | `--wa-chat-accent-ink` |
| `--wa-chat-color-danger` | `#c62828` | `#ff8a80` | `--wa-chat-danger` |
| `--wa-chat-color-success` | `#1b7f3b` | `#6fcf8f` | `--wa-chat-success` |
| `--wa-chat-color-user-bubble` | follows `--wa-chat-color-accent` |  |  |
| `--wa-chat-color-user-bubble-ink` | follows `--wa-chat-color-accent-ink` |  |  |
| `--wa-chat-color-assistant-bubble` | follows `--wa-chat-color-soft` |  |  |
| `--wa-chat-color-assistant-bubble-ink` | follows `--wa-chat-color-fg` |  |  |
| `--wa-chat-color-tool-bg` | `transparent` |  |  |
| `--wa-chat-color-tool-line` | follows `--wa-chat-color-line` |  |  |
| `--wa-chat-color-input-bg` | follows `--wa-chat-color-bg` |  |  |
| `--wa-chat-color-input-line` | follows `--wa-chat-color-line` |  |  |
| `--wa-chat-color-focus-ring` | follows `--wa-chat-color-accent` |  |  |
| `--wa-chat-color-overlay` | `color-mix(in srgb, var(--wa-chat--color-fg) 6%, var(--wa-chat--color-bg))` |  |  |
| `--wa-chat-color-error-bg` | `color-mix(in srgb, var(--wa-chat--color-danger) 10%, transparent)` |  |  |
| `--wa-chat-font-family` | `system-ui, -apple-system, "Segoe UI", Roboto, sans-serif` |  | `--wa-chat-font` |
| `--wa-chat-font-mono` | `ui-monospace, "SF Mono", Menlo, monospace` |  |  |
| `--wa-chat-font-size` | `14px` |  |  |
| `--wa-chat-font-size-small` | `13px` |  |  |
| `--wa-chat-font-size-x-small` | `12px` |  |  |
| `--wa-chat-font-size-title` | `15px` |  |  |
| `--wa-chat-font-size-input` | `16px` |  |  |
| `--wa-chat-font-line-height` | `1.5` |  |  |
| `--wa-chat-font-line-height-tight` | `1.4` |  |  |
| `--wa-chat-font-weight` | `500` |  |  |
| `--wa-chat-font-weight-strong` | `600` |  |  |
| `--wa-chat-radius-panel` | `14px` |  | `--wa-chat-radius` |
| `--wa-chat-radius-bubble` | `max(0px, calc(var(--wa-chat-radius-panel, 14px) - 2px))` |  |  |
| `--wa-chat-radius-card` | `max(0px, calc(var(--wa-chat-radius-panel, 14px) - 4px))` |  |  |
| `--wa-chat-radius-control` | `max(0px, calc(var(--wa-chat-radius-panel, 14px) - 6px))` |  |  |
| `--wa-chat-radius-launcher` | `999px` |  |  |
| `--wa-chat-radius-pill` | `999px` |  |  |
| `--wa-chat-space-gap` | `20px` |  | `--wa-chat-gap` |
| `--wa-chat-space-pad` | `16px` |  |  |
| `--wa-chat-space-pad-bubble` | `8px 12px` |  |  |
| `--wa-chat-space-inset-bottom` | follows `--wa-chat-space-gap` |  |  |
| `--wa-chat-space-xxs` | `2px` |  |  |
| `--wa-chat-space-xs` | `4px` |  |  |
| `--wa-chat-space-sm` | `6px` |  |  |
| `--wa-chat-space-md` | `8px` |  |  |
| `--wa-chat-space-lg` | `10px` |  |  |
| `--wa-chat-space-xl` | `12px` |  |  |
| `--wa-chat-space-xxl` | `14px` |  |  |
| `--wa-chat-size-width` | `400px` |  |  |
| `--wa-chat-size-max-height` | `620px` |  |  |
| `--wa-chat-size-viewport-gap` | `120px` |  |  |
| `--wa-chat-size-dock-width` | `380px` |  |  |
| `--wa-chat-size-sheet-height` | `min(85dvh, 640px)` |  |  |
| `--wa-chat-size-launcher` | `52px` |  |  |
| `--wa-chat-size-icon` | `36px` |  |  |
| `--wa-chat-size-button` | `36px` |  |  |
| `--wa-chat-size-control` | `32px` |  |  |
| `--wa-chat-size-target` | `24px` |  |  |
| `--wa-chat-size-input-min-height` | `40px` |  |  |
| `--wa-chat-size-input-max-height` | `calc(6lh + 18px)` |  |  |
| `--wa-chat-size-bubble-max` | `88%` |  |  |
| `--wa-chat-size-dot` | `7px` |  |  |
| `--wa-chat-size-typing-dot` | `6px` |  |  |
| `--wa-chat-size-progress` | `6px` |  |  |
| `--wa-chat-size-handle` | `8px` |  |  |
| `--wa-chat-size-border` | `1px` |  |  |
| `--wa-chat-size-focus-ring` | `2px` |  |  |
| `--wa-chat-size-focus-offset` | `2px` |  |  |
| `--wa-chat-size-accent-border` | `3px` |  |  |
| `--wa-chat-size-underline-offset` | `3px` |  |  |
| `--wa-chat-shadow-panel` | `0 12px 40px rgba(15, 23, 42, 0.16), 0 2px 6px rgba(15, 23, 42, 0.08)` |  | `--wa-chat-shadow` |
| `--wa-chat-shadow-launcher` | follows `--wa-chat-shadow-panel` |  |  |
| `--wa-chat-shadow-card` | follows `--wa-chat-shadow-panel` |  |  |
| `--wa-chat-shadow-control` | `0 1px 2px rgba(15, 23, 42, 0.12)` |  |  |
| `--wa-chat-shadow-chip` | `0 0 0 1px var(--wa-chat--color-line), 0 1px 2px rgba(15, 23, 42, 0.08)` |  |  |
| `--wa-chat-motion-ease` | `var(--agent-ease-out, cubic-bezier(0.22, 1, 0.36, 1))` |  | `--wa-chat-ease` |
| `--wa-chat-motion-duration` | `0.18s` |  |  |
| `--wa-chat-motion-duration-fast` | `0.15s` |  |  |
| `--wa-chat-motion-duration-slow` | `0.3s` |  |  |
| `--wa-chat-motion-duration-fade` | `120ms` |  |  |
| `--wa-chat-motion-duration-loop` | `1.2s` |  |  |
| `--wa-chat-motion-duration-pulse` | `1.6s` |  |  |
| `--wa-chat-motion-offset` | `8px` |  |  |
| `--wa-chat-motion-slide` | `16px` |  |  |
| `--wa-chat-motion-bounce` | `3px` |  |  |
| `--wa-chat-motion-pulse` | `12px` |  |  |
| `--wa-chat-z-handle` | `1` |  |  |
| `--wa-chat-z` | `calc(var(--agent-z, 2147483000) - 2)` |  | `--wa-chat-z` |

## Keep it readable

Check the pairs you change against each other, in light and in dark. WCAG 2.2 asks for:

| Pair | Minimum contrast |
|---|---|
| `color-fg` on `color-bg`, `color-assistant-bubble-ink` on `color-assistant-bubble` | 4.5:1 |
| `color-accent-ink` on `color-accent`, `color-user-bubble-ink` on `color-user-bubble` | 4.5:1 |
| `color-muted` on `color-bg` (timestamps, hints) | 4.5:1 |
| `color-danger` on `color-error-bg` (error messages) | 4.5:1 |
| `color-focus-ring` against `color-bg` and against the control it surrounds | 3:1 |
| `color-line` and `color-input-line` against `color-bg` (borders that show a control's edge) | 3:1 |

Text of 18.66px bold or 24px and larger needs 3:1. The defaults meet these. A brand color is often too light for white
text: pick `color-accent-ink` for it rather than assuming white, and check the dark scheme separately, since a theme
value you set without `light` and `dark` applies to both.

## The 0.4.0 names still work

The eighteen variables of 0.4.0 (`--wa-chat-accent`, `--wa-chat-bg`, `--wa-chat-radius`, `--wa-chat-font`…) are still
declared on `.wa-chat`, with the same dark rules, and each one is the default of its new token (the "0.4.0 name"
column). A page that set them keeps the look it had. Two differences when you move to the new names:

- A new token set on `:root` applies in both schemes. A 0.4.0 name set on `.wa-chat` applies in light only, because
  the chat's dark rules redefine it.
- `--wa-chat-radius` still draws only the panel. The bubble, card and control radii follow `--wa-chat-radius-panel`.

## Test it

[Test the chat UI](/docs/testing/test-the-chat) renders the chat with your props and checks that no string is left outside
the catalog.
