Skip to main content

Message

Preview

One message of a chat, a person's message in a bubble or the assistant's answer as full-width prose. Each Message.Root renders an <li>, so put it in Conversation's Conversation.Content.

Desktop viewport
Tablet viewport
Mobile viewport

When to use

  • Show one message of a chat with an assistant or a model, with actions such as copy.
  • Show a marker while the answer is on its way.
  • Use Conversation for the transcript that holds the messages.

An answer on its way

Render Message.Pending under the part of the answer that arrived, until the answer ends. A first sentence such as "Let me check your endpoints." can come before seconds of tool calls, so keep the marker after the first text. It is not a live region: Conversation.Root announces the start and the end of the answer once.

Desktop viewport
Tablet viewport
Mobile viewport

Composition

Message.Root├── Message.Content├── Message.Pending└── Message.Actions

Polymorphism

Message.Root and Message.Actions take asChild. Message.Content and Message.Pending do not, because each renders an element beside its children.

Accessibility

Message.Content starts with a visually hidden speaker label, "You said:" or "The assistant said:", so a screen reader says who wrote each message.

Translation

Message.Content and Message.Pending render an element beside their children: the speaker label and the pulsing dot. Each wraps the children in a display: contents element (message-content-label and message-pending-label), so a page that a browser translates survives a change to them.

API Reference

Message.Root

One message: an <li> that lays out the content, the actions, and any pending marker.

All props from li, plus:

PropTypeDefaultDescription
from"user" | "assistant"Who wrote the message. Required. A person's message sits at the end of the row in a bubble.
asChild?booleanfalseRender as a different element by passing a child.
Data AttributeValueDescription
data-from"user" or "assistant"Who wrote the message. Style with data-[from=user]:.

Message.Content

The body of a message: a bubble for a person, full-width prose for the assistant.

All props from div.

Data AttributeValueDescription
data-slot="message-content-label"on the wrapperThe display: contents wrapper around the children.

Message.Pending

A marker with a pulsing dot that an answer is on its way, such as "Thinking…".

All props from div.

Data AttributeValueDescription
data-slot="message-pending-label"on the wrapperThe display: contents wrapper around the children.

Message.Actions

A row of small actions and facts under a message, such as a copy button.

All props from div, plus:

PropTypeDefaultDescription
asChild?booleanfalseRender as a different element by passing a child.