# Message

A complete message row with markdown content and inline action buttons.

> For the complete documentation index, see [llms.txt](/llms.txt). Markdown variants are available by appending `.md` to any URL or sending an `Accept: text/markdown` header. An agent skill is available at [/.well-known/agent-skills/site-skill.md](/.well-known/agent-skills/site-skill.md).

<ComponentPreview name="message-demo" title="message-demo.tsx" src="examples/message-demo.tsx">
<MessageDemo />
</ComponentPreview>

Message Pattern shows a user turn and an assistant turn with the pieces that make a real conversation feel finished: markdown content, a copy action, feedback buttons, and a retry action. It composes Message, Bubble, Tooltip, Button, and Markdown.

Message is a **composition**, not a primitive. Install the five primitives it uses, then wire it the same way the demo does.

## Installation [#installation]

<CodeTabs>
<TabsList>
<TabsTrigger value="cli">
Command
</TabsTrigger>

<TabsTrigger value="manual">
Manual
</TabsTrigger>
</TabsList>

<TabsContent value="cli">
```bash
npx frakment add message bubble tooltip button
```
</TabsContent>

<TabsContent value="manual">
<Steps>
<Step>
Install the following dependencies:
</Step>

```bash
npm install radix-ui lucide-react
```

<Step>
Install the required registry primitives:
</Step>

<ComponentSource name="message" title="components/ui/message.tsx" />

<ComponentSource name="bubble" title="components/ui/bubble.tsx" />

<ComponentSource name="tooltip" title="components/ui/tooltip.tsx" />

<ComponentSource name="button" title="components/ui/button.tsx" />

<ComponentSource src="components/ui/markdown.tsx" title="components/ui/markdown.tsx" />

<Step>
Update the import paths to match your project setup.
</Step>
</Steps>
</TabsContent>
</CodeTabs>

## Usage [#usage]

```tsx title="message-demo.tsx"
import { Markdown } from "@/components/ui/markdown";
import { Bubble, BubbleContent } from "@/components/ui/message";
import { Button } from "@/components/ui/button";
import {
  Message,
  MessageContent,
  MessageFooter,
} from "@/components/ui/message";
import {
  Tooltip,
  TooltipContent,
  TooltipTrigger,
} from "@/components/ui/tooltip";

<Message>
  <MessageContent className="gap-2">
    <Markdown>{reply}</Markdown>
    <MessageFooter className="px-0">
      <MessageAction label="Copy"><CopyIcon /></MessageAction>
      <MessageAction label="Retry"><RefreshCcwIcon /></MessageAction>
    </MessageFooter>
  </MessageContent>
</Message>
```

## Anatomy [#anatomy]

```tsx title="message-demo.tsx"
<Message align="end">
  <MessageContent>
    <Bubble align="end" variant="muted">
      <BubbleContent>{userText}</BubbleContent>
    </Bubble>
    <MessageFooter>
      <MessageAction label="Copy"><CopyIcon /></MessageAction>
      <MessageAction label="Edit"><PencilIcon /></MessageAction>
    </MessageFooter>
  </MessageContent>
</Message>

<Message>
  <MessageContent>
    <Markdown>{reply}</Markdown>
    <MessageFooter>
      <MessageAction label="Copy"><CopyIcon /></MessageAction>
      <MessageAction label="Good response"><ThumbsUpIcon /></MessageAction>
      <MessageAction label="Bad response"><ThumbsDownIcon /></MessageAction>
      <MessageAction label="Retry"><RefreshCcwIcon /></MessageAction>
    </MessageFooter>
  </MessageContent>
</Message>
```

- **Message** — the row, with `align` for user (`end`) or assistant (`start`).
- **MessageContent** — vertical stack for bubble + footer.
- **Bubble**, **BubbleContent** — the surface for the user message.
- **Markdown** — renders the assistant reply, including fenced code blocks.
- **MessageFooter** — horizontal action row aligned to the message.
- **MessageAction** — a Button wrapped in a Tooltip, with `aria-label` for the icon.

## Copy feedback [#copy-feedback]

The copy action swaps to a checkmark for two seconds after clicking. Wire it with a single state:

```tsx
const [copied, setCopied] = React.useState(false);
React.useEffect(() => {
  if (!copied) return;
  const t = setTimeout(() => setCopied(false), 2000);
  return () => clearTimeout(t);
}, [copied]);
```

## Feedback toggle [#feedback-toggle]

Like and dislike are independent toggles. Track a single `feedback` state and use `aria-pressed` so screen readers announce the state:

```tsx
<MessageAction
  aria-pressed={feedback === "like"}
  label="Good response"
  onClick={() => setFeedback(feedback === "like" ? null : "like")}
>
  <ThumbsUpIcon className={feedback === "like" ? "fill-current" : undefined} />
</MessageAction>
```

## Best Practices [#best-practices]

- **Only show actions after the response finishes streaming.** A copy button on a partially-streamed reply copies incomplete text.
- **Use real buttons, not styled text.** `MessageAction` renders a `Button` inside a `Tooltip` — keep that structure so keyboard users can reach it.
- **Icon-only actions need a label.** Pass `aria-label` and put the same string in the tooltip.
- **Keep the footer aligned with the message.** Do not use `justify-between` to spread the actions; they cluster.
- **Do not nest interactive content inside Bubble.** Actions belong in `MessageFooter`.

## Accessibility [#accessibility]

- Each `MessageAction` is a real `<button>` with `aria-label` matching its tooltip.
- Feedback toggles use `aria-pressed` so screen readers announce "pressed" or "not pressed".
- The copy state is announced via the tooltip and the swapped icon; the button keeps its accessible name throughout.
- Code blocks render inside `Markdown` and preserve syntax highlighting for screen readers.

## Next [#next]

- [Chat](/docs/ai-elements/chat) — full streaming chat surface.
- [Message](/docs/components/message) — message row primitive.
- [Bubble](/docs/components/bubble) — chat bubble surface.
- `Markdown` — render markdown with code blocks.