Message
Lays out one row of a conversation, with an avatar, a sender line, the message itself and a footer for status and actions.
Component, not pattern
This page is the layout component Message in components/ui/message. The AI pattern with the same name, which composes it with markdown, tools and reasoning, is documented at AI Elements: Message.
Installation
pnpm dlx shadcn@latest add @silkware/messageTo copy the component by hand, install its dependencies:
pnpm add cnThen copy the source into components/ui/message.tsx:
import * as React from "react"import { cn } from "cn"
function MessageGroup({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="message-group" className={cn("flex min-w-0 flex-col gap-2", className)} {...props} /> )}
function Message({ className, align = "start", ...props}: React.ComponentProps<"div"> & { align?: "start" | "end" }) { return ( <div data-slot="message" data-align={align} className={cn( "group/message relative flex w-full min-w-0 gap-2 text-sm data-[align=end]:flex-row-reverse", className )} {...props} /> )}
function MessageAvatar({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="message-avatar" className={cn( "flex w-fit min-w-8 shrink-0 items-center justify-center self-end overflow-hidden rounded-full bg-muted group-has-data-[slot=message-footer]/message:-translate-y-8", className )} {...props} /> )}
function MessageContent({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="message-content" className={cn( "flex w-full min-w-0 flex-col gap-2.5 wrap-break-word group-data-[align=end]/message:*:data-slot:self-end", className )} {...props} /> )}
function MessageHeader({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="message-header" className={cn( "flex max-w-full min-w-0 items-center px-3 text-xs font-medium text-muted-foreground group-has-data-[variant=ghost]/message:px-0", className )} {...props} /> )}
function MessageFooter({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="message-footer" className={cn( "flex max-w-full min-w-0 items-center px-3 text-xs font-medium text-muted-foreground group-has-data-[variant=ghost]/message:px-0 group-data-[align=end]/message:justify-end", className )} {...props} /> )}
export { MessageGroup, Message, MessageAvatar, MessageContent, MessageFooter, MessageHeader,}Usage
import { Message, MessageAvatar, MessageContent, MessageFooter, MessageGroup, MessageHeader,} from "@/components/ui/message"<Message> <MessageAvatar> <Avatar> <AvatarFallback>LU</AvatarFallback> </Avatar> </MessageAvatar> <MessageContent> <MessageHeader>Luca</MessageHeader> <Bubble variant="muted"> <BubbleContent>Can you check the Verona stock?</BubbleContent> </Bubble> </MessageContent></Message>Message owns the row: which side it sits on, where the avatar goes, and the header and footer. It draws no surface. Put a Bubble in MessageContent for the surface, and put the rows in a Message Scroller when the conversation scrolls. Set align on the Message; the bubble, the header and the footer follow it.
Examples
Avatar
MessageAvatar holds an Avatar at the bottom of the row. With align="end" the row and the avatar move to the end.
Group
MessageGroup stacks consecutive messages from one sender. Render an empty MessageAvatar on the earlier rows so that all the bubbles line up with the avatar on the last one.
Header and footer
MessageHeader holds the sender and the time above the bubble. MessageFooter holds status below it. The header and the footer follow align: with align="end" both move to the end.
Actions
Put the actions that belong to one message in MessageFooter: copy, ask again, send again. A failed send reads best as text with a retry button. When the footer is present, the avatar moves up to stay level with the bubble.
Attachment
Put an Attachment in MessageContent, before or after the bubble, for a file that belongs to the message.
Status
A turn that is still being worked on is a Marker with role="status" and a Spinner, in place of a bubble. Screen readers announce the text when it appears.
Accessibility
Message is layout. It sets no role and no label, and it has no keyboard behaviour. The keys below apply to the controls you put in its footer.
| Key | Action |
|---|---|
| Tab | Moves focus to each button or link in the message, in reading order. |
| Enter | Presses the focused button. |
| Space | Presses the focused button. |
The component provides:
- Source order that matches reading order. Visual order changes with
alignthroughflex-direction, so the avatar comes first in the DOM on both sides and the text is read in order. - Wrapping of long words in the content, so a long file name or code does not push the row wider.
You provide:
- The sender, in text: a
MessageHeader, or a heading or label in your transcript. A side and a colour do not tell a screen reader who is speaking. - An
aria-labelon every icon button in the footer, naming the action: "Copy the answer", "Send again". - A live region when messages arrive on their own. Wrap the list in a Message Scroller, whose content is a
log, or userole="status"on a Marker for a status line. - Alt text on avatars that carry a name or face, and an empty one when the sender is already in the header.
Guidelines
When to use
- For each row of a chat: the person, other people, an agent.
- For a message thread on an order, a supplier or a ticket, where each entry has an author and a time.
When not to use
- For a comment attached to a field or a row in a table. Use a Popover or an Item.
- For a notice about the page. Use an Alert.
- For an entry in an activity log with no conversation. Use a Table or a list of Items.
- For the surface of the message on its own. Use a Bubble.
Content
- Name the sender in the header: first name, and the time when it matters. An agent is named after what it is, for example "Agentic OS".
- Keep the footer for facts about the message: delivery, read, failed, and the actions that act on it.
- Write status in plain words: "Read 09:16", "Not sent". Do not use "Sent!" or an icon alone.
- One message in a row says one thing. Use a group of messages for several.
Sender
Show who is speaking wherever more than two parties can talk, and in every transcript that is read out of context, such as a copy or an export.
Name the sender in a header so the message does not depend on its side or colour.
Don’t leave the sender to the layout. In a thread with several people, a screen reader reads a message with no author.
Label each icon action in the footer with what it does to this message.
Don’t put icon buttons in the footer without a label. They are announced as unnamed buttons.
API reference
Message
Renders a <div>, a flex row of avatar and content that fills the width. It accepts every prop of a div. The installed component has no role prop for the sender; use align.
| Prop | Type | Default | Description |
|---|---|---|---|
align? | "start" | "end" | "start" | The side of the conversation the row sits on. A Bubble and the footer inside it follow. |
className? | string | None | Classes merged after the row classes. |
MessageGroup
Renders a <div> that stacks messages with a small gap.
| Prop | Type | Default | Description |
|---|---|---|---|
className? | string | None | Classes merged after the layout classes. |
MessageAvatar
Renders a <div> pinned to the bottom of the row for an Avatar. An empty one keeps the space of an avatar.
| Prop | Type | Default | Description |
|---|---|---|---|
children? | ReactNode | None | An Avatar. Leave it out to keep the space empty. |
className? | string | None | Classes merged after the avatar slot classes. |
MessageContent
Renders a <div> that holds the header, the bubble or attachments, and the footer, in a column.
| Prop | Type | Default | Description |
|---|---|---|---|
className? | string | None | Classes merged after the content classes. |
MessageHeader
Renders a <div> above the content, in small muted type, for the sender and the time. It stays at the start of the row.
| Prop | Type | Default | Description |
|---|---|---|---|
className? | string | None | Classes merged after the header classes. |
MessageFooter
Renders a <div> below the content, in small muted type, for status and actions. With align="end" it is pushed to the end.
| Prop | Type | Default | Description |
|---|---|---|---|
className? | string | None | Classes merged after the footer classes. |