Composable user and assistant message layouts for AI chat.
Use ChatMessage.User for the user's turn and ChatMessage.Assistant for the reply.
import {ChatMessage, ChatMessageActions} from "@heroui-pro/react";
<ChatMessage.User>
<ChatMessage.Bubble>
<ChatMessage.Content>{/* ... */}</ChatMessage.Content>
</ChatMessage.Bubble>
</ChatMessage.User>;
<ChatMessage.Assistant>
<ChatMessage.Avatar alt="Assistant" fallback="AI" /> {/* Optional */}
<ChatMessage.Body>
<ChatMessage.Content>{/* ... */}</ChatMessage.Content>
<ChatMessage.Media>{/* ... */}</ChatMessage.Media> {/* Optional */}
<ChatMessageActions> {/* Optional */}
<ChatMessageActions.Copy aria-label="Copy" tooltip="Copy" />
</ChatMessageActions>
</ChatMessage.Body>
</ChatMessage.Assistant>;Render the reply with Markdown inside ChatMessage.Content.
Set variant="card" on ChatMessage.Assistant to place a whole turn on a Card surface: the reasoning, the answer, a Separator, and the sources. The card doesn't space the Separator, so add a class such as mt-1.
Show TextShimmer and a dots Loader while the reply streams, or ChatLoader.Skeleton before it starts.
HeroUI follows the BEM methodology to ensure component variants and states are reusable and easy to customize.
The Chat Message component uses these CSS classes:
.chat-message--user: User message wrapper.chat-message--assistant: Assistant message row.chat-message__avatar: Avatar.chat-message__avatar-spacer: Empty space in place of the avatar.chat-message__body: Assistant body column.chat-message__bubble: User bubble.chat-message__content: Message text.chat-message__media: Media column.chat-message__actions: Action row, fully visible on hover and focus.chat-message__action: Action button.chat-message--card: Assistant card variant[data-variant="default|card"] on .chat-message--assistant: Assistant variantSupports native div props.
User and assistant messages fill their container, so set the width on the conversation column. Chat apps usually cap it around 680–768px on desktop and let it run full width on mobile.
Supports native div props.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "default" | "card" | "default" | card places the turn on a Card surface |
Supports native div props. With show={false}, the spacer is hidden from screen readers.
| Prop | Type | Default | Description |
|---|---|---|---|
alt | string | - | Alternative text for the src image |
src | string | - | Image URL |
fallback | string | - | Text shown without an image, such as initials |
show | boolean | true | When false, renders a same-size spacer for grouped messages |
The assistant's content column. Supports native div props.
The user's message bubble. Supports native div props.
Message text. Supports native div props.
A column for images, charts, or attachments. Supports native div props.
The same component as ChatMessageActions, with its preset actions for copy, rating, or retry. Prefer ChatMessageActions.
An icon-only ghost button, the same component as ChatMessageActions.Action. Extends HeroUI Button props.
| Prop | Type | Default | Description |
|---|---|---|---|
aria-label | string | - | Accessible name of the icon button |
tooltip | ReactNode | - | Tooltip shown on hover and focus |
aria-label. Set tooltip to show the same name on hover and focus.log region, so set aria-busy on it while a reply streams.Resources