Skip to content

Message

Lays out one row of a conversation, with an avatar, a sender line, the message itself and a footer for status and actions.

LU
Luca
Can you check the Verona stock before we order?
Checked. We have 40 units left.

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/message

To copy the component by hand, install its dependencies:

pnpm add cn

Then copy the source into components/ui/message.tsx:

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.

GI
The price list needs your approval.
MA
I will look at it after lunch.

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.

I checked the Padova delivery.
MA
It arrives on Thursday, not Tuesday.

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.

Giulia · 09:14
I approved order 4417.
Thanks. I will send it to Lamivo Metalli.
Read 09:16

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.

Three orders wait for approval. The oldest is order 4409.
Send the approved orders today.
Not sent

Attachment

Put an Attachment in MessageContent, before or after the bubble, for a file that belongs to the message.

Export the 2026 price list for the Verona site.
Done. The list has 312 rows.
2026-pricelist.xlsxXLSX · 212 KB

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.

Which orders are late?
Checking 38 open orders

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.

KeyAction
TabMoves focus to each button or link in the message, in reading order.
EnterPresses the focused button.
SpacePresses the focused button.

The component provides:

  • Source order that matches reading order. Visual order changes with align through flex-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-label on 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 use role="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.

Marco
Batch 2291 passed inspection.
Do

Name the sender in a header so the message does not depend on its side or colour.

Batch 2291 passed inspection.
Don’t

Don’t leave the sender to the layout. In a thread with several people, a screen reader reads a message with no author.

Order 4417 ships on Thursday.
Do

Label each icon action in the footer with what it does to this message.

Order 4417 ships on Thursday.
Don’t

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.

PropTypeDefaultDescription
align?"start" | "end""start"The side of the conversation the row sits on. A Bubble and the footer inside it follow.
className?stringNoneClasses merged after the row classes.

MessageGroup

Renders a <div> that stacks messages with a small gap.

PropTypeDefaultDescription
className?stringNoneClasses 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.

PropTypeDefaultDescription
children?ReactNodeNoneAn Avatar. Leave it out to keep the space empty.
className?stringNoneClasses merged after the avatar slot classes.

MessageContent

Renders a <div> that holds the header, the bubble or attachments, and the footer, in a column.

PropTypeDefaultDescription
className?stringNoneClasses 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.

PropTypeDefaultDescription
className?stringNoneClasses 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.

PropTypeDefaultDescription
className?stringNoneClasses merged after the footer classes.