Bubble
Displays conversational content in a message bubble. Supports variants, alignment, grouping, reactions, and collapsible content.
import {
Bubble,
BubbleContent,
BubbleGroup,
BubbleReactions
} from "~/components/ui/bubble"
export default function BubbleDemo() {
return (
<div class="flex w-full max-w-sm flex-col gap-8 py-12">
<Bubble align="end">
<BubbleContent>Hey there! what's up?</BubbleContent>
</Bubble>
<BubbleGroup>
<Bubble variant="muted">
<BubbleContent>Hey! Want to see chat bubbles?</BubbleContent>
</Bubble>
<Bubble variant="muted">
<BubbleContent>
I can group messages, switch sides, and keep the whole thread easy
to scan.
</BubbleContent>
<BubbleReactions role="img" aria-label="Reaction: thumbs up">
<span>👍</span>
</BubbleReactions>
</Bubble>
</BubbleGroup>
<Bubble align="end">
<BubbleContent>Sure. Hit me with your best demo.</BubbleContent>
</Bubble>
<Bubble variant="muted">
<BubbleContent>
Yes. You are reading a demo that is demoing itself. Very meta. Very
on-brand.
</BubbleContent>
<BubbleReactions
role="img"
aria-label="Reactions: thumbs up, fire, eyes, and 2 more"
>
<span>👍</span>
<span>🔥</span>
<span>👀</span>
<span>+2</span>
</BubbleReactions>
</Bubble>
</div>
)
}The Bubble component displays framed conversational content. Use it for chat text, short structured output, quoted replies, suggestions, and reactions.
For full-featured chat interfaces, use the Message component. Bubble is intentionally scoped to the bubble surface. Place avatars, names, timestamps, metadata, and message-level actions in Message.
Installation
Install the following dependencies:
Copy and paste the following code into your project.
import { dynamic, type ComponentProps, type JSX } from "@solidjs/web"
import { cva, type VariantProps } from "class-variance-authority"
import { isStatic, omit } from "solid-js"
import { cn } from "~/lib/utils"
const bubbleVariants = cva(
"max-w-[80%] gap-1 group-data-[align=end]/message:self-end data-[align=end]:self-end data-[variant=ghost]:max-w-full group/bubble relative flex w-fit min-w-0 flex-col",
{
variants: {
variant: {
default: "*:data-[slot=bubble-content]:bg-primary *:data-[slot=bubble-content]:text-primary-foreground [&>[data-slot=bubble-content]:is(button,a):hover]:bg-primary/80",
secondary: "*:data-[slot=bubble-content]:bg-secondary *:data-[slot=bubble-content]:text-secondary-foreground [&>[data-slot=bubble-content]:is(button,a):hover]:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)]",
muted: "*:data-[slot=bubble-content]:bg-muted [&>[data-slot=bubble-content]:is(button,a):hover]:bg-[color-mix(in_oklch,var(--muted),var(--foreground)_5%)]",
tinted: "*:data-[slot=bubble-content]:bg-[oklch(from_var(--primary)_0.93_calc(c*0.4)_h)] *:data-[slot=bubble-content]:text-foreground dark:*:data-[slot=bubble-content]:bg-[oklch(from_var(--primary)_0.3_calc(c*0.4)_h)] [&>[data-slot=bubble-content]:is(button,a):hover]:bg-[oklch(from_var(--primary)_0.88_calc(c*0.5)_h)] dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-[oklch(from_var(--primary)_0.35_calc(c*0.5)_h)]",
outline: "*:data-[slot=bubble-content]:border-border *:data-[slot=bubble-content]:bg-background [&>[data-slot=bubble-content]:is(button,a):hover]:bg-muted [&>[data-slot=bubble-content]:is(button,a):hover]:text-foreground dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-input/30",
ghost: "border-none *:data-[slot=bubble-content]:rounded-none *:data-[slot=bubble-content]:bg-transparent *:data-[slot=bubble-content]:p-0 [&>[data-slot=bubble-content]:is(button,a):hover]:bg-muted [&>[data-slot=bubble-content]:is(button,a):hover]:text-foreground dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-muted/50",
destructive: "*:data-[slot=bubble-content]:bg-destructive/10 *:data-[slot=bubble-content]:text-destructive dark:*:data-[slot=bubble-content]:bg-destructive/20 [&>[data-slot=bubble-content]:is(button,a):hover]:bg-destructive/20 dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-destructive/30"
}
},
defaultVariants: {
variant: "default"
}
}
)
const bubbleReactionsVariants = cva(
"shrink-0 gap-1 rounded-full bg-muted px-1.5 py-0.5 text-sm ring-3 ring-card has-[button]:p-0 absolute z-10 flex w-fit items-center justify-center",
{
variants: {
side: {
top: "top-0 -translate-y-3/4",
bottom: "bottom-0 translate-y-3/4"
},
align: {
start: "left-3",
end: "right-3"
}
},
defaultVariants: {
side: "bottom",
align: "end"
}
}
)
export function BubbleGroup(
props: Omit<ComponentProps<"div">, "class"> & { class?: string }
) {
return (
<div
{...props}
data-slot="bubble-group"
class={cn("gap-2 flex min-w-0 flex-col", props.class)}
/>
)
}
export function Bubble(
props: Omit<ComponentProps<"div">, "class"> & {
class?: string
align?: "start" | "end"
variant?: VariantProps<typeof bubbleVariants>["variant"]
}
) {
const rest = omit(props, "class", "align", "variant")
return (
<div
{...rest}
data-slot="bubble"
data-align={props.align ?? "start"}
data-variant={props.variant ?? "default"}
class={cn(
bubbleVariants({ variant: props.variant ?? "default" }),
props.class
)}
/>
)
}
export function BubbleContent(
props: ComponentProps<"div"> & {
render?: (
props: Record<string, unknown> & { class: string; children?: JSX.Element }
) => JSX.Element
}
) {
const Comp = dynamic(() => props.render ?? "div", {
static: isStatic(props, "render")
})
const rest = omit(props, "class", "render")
return (
<Comp
data-slot="bubble-content"
class={cn(
"rounded-xl border border-transparent px-3 py-2 text-sm leading-relaxed group-data-[align=end]/bubble:self-end [button,a]:outline-none [button,a]:focus-visible:border-ring [button,a]:focus-visible:ring-3 [button,a]:focus-visible:ring-ring/50 w-fit max-w-full min-w-0 overflow-hidden wrap-break-word",
props.class
)}
{...rest}
/>
)
}
export function BubbleReactions(
props: Omit<ComponentProps<"div">, "class"> & {
class?: string
side?: "top" | "bottom"
align?: "start" | "end"
}
) {
const rest = omit(props, "class", "side", "align")
return (
<div
{...rest}
data-slot="bubble-reactions"
data-side={props.side ?? "bottom"}
data-align={props.align ?? "end"}
class={cn(
bubbleReactionsVariants({
side: props.side ?? "bottom",
align: props.align ?? "end"
}),
props.class
)}
/>
)
}Update the import paths to match your project setup.
Usage
import { Bubble, BubbleContent } from "~/components/ui/bubble"<Bubble>
<BubbleContent>I checked the registry output.</BubbleContent>
</Bubble>Use variant on Bubble, align for start/end, and side/align on BubbleReactions. Content uses native div markup. Use semantic buttons or links inside content for interactive elements.
Composition
Use the following composition to build a bubble:
Bubble
├── BubbleContent
└── BubbleReactionsUse BubbleGroup to group consecutive bubbles from the same sender:
BubbleGroup
├── Bubble
│ └── BubbleContent
└── Bubble
└── BubbleContentFeatures
- Seven visual variants, from a strong primary bubble to unframed ghost content
- Start and end alignment for sender and receiver bubbles
- Reactions that anchor to the bubble edge with configurable side and alignment
- Bubbles size to their content, up to 80% of the container width
- Polymorphic content via
renderfor link and button bubbles - Customizable styling through the
classprop on every part
Variants
Use variant to change the visual treatment of the bubble.
Ghost bubbles work for assistant text, markdown, and other content that should not be framed.
This is perfect for assistant messages that should not have a frame and can take the full width of the container. You can also render code in it.
Ghost bubbles are full width and can take the full width of the container.
import { Bubble, BubbleContent, BubbleReactions } from "~/components/ui/bubble"
export default function BubbleVariantsDemo() {
return (
<div class="flex w-full max-w-sm flex-col gap-12 py-12">
<Bubble>
<BubbleContent>This is the default primary bubble.</BubbleContent>
</Bubble>
<Bubble variant="secondary" align="end">
<BubbleContent>This is the secondary variant.</BubbleContent>
</Bubble>
<Bubble variant="muted">
<BubbleContent>
This one is muted. It uses a lower emphasis color for the chat bubble.
</BubbleContent>
<BubbleReactions role="img" aria-label="Reaction: thumbs up">
<span>👍</span>
</BubbleReactions>
</Bubble>
<Bubble variant="tinted" align="end">
<BubbleContent>
This one is tinted. The tint is a softer color derived from the
primary color.
</BubbleContent>
</Bubble>
<Bubble variant="outline">
<BubbleContent>We can also use an outlined variant.</BubbleContent>
</Bubble>
<Bubble variant="destructive" align="end">
<BubbleContent>Or a destructive variant with a reaction.</BubbleContent>
<BubbleReactions role="img" aria-label="Reaction: fire">
<span>🔥</span>
</BubbleReactions>
</Bubble>
<Bubble variant="ghost">
<BubbleContent>
<div class="space-y-3">
<p>
Ghost bubbles work for assistant text, <strong>markdown</strong>,
and other content that should not be framed.
</p>
<p>
This is perfect for assistant messages that should not have a
frame and can take the full width of the container. You can also
render <code>code</code> in it.
</p>
<p>
Ghost bubbles are full width and can take the full width of the
container.
</p>
</div>
</BubbleContent>
</Bubble>
</div>
)
}A bubble sizes to its content, up to 80% of the container width. The ghost variant removes the max-width so assistant text and rich content can span the full row.
Alignment
Use align on Bubble to align the bubble to the start or end of the conversation.
import { Bubble, BubbleContent } from "~/components/ui/bubble"
export default function BubbleAlignmentDemo() {
return (
<div class="flex w-full max-w-sm flex-col gap-8 py-12">
<Bubble variant="muted">
<BubbleContent>
This bubble is aligned to the start. This is the default alignment.
</BubbleContent>
</Bubble>
<Bubble align="end">
<BubbleContent>
This bubble is aligned to the end. Use this for user messages.
</BubbleContent>
</Bubble>
</div>
)
}Note: When building chat interfaces, you probably want to use alignment on the Message component itself, not the Bubble component. You can use the role prop on the Message component to automatically align the bubble to the start or end of the conversation.
Bubble Group
Use BubbleGroup to group consecutive bubbles from the same sender. Note the align prop should be set on the Bubble component itself, not the BubbleGroup component.
BubbleGroup
├── Bubble
│ └── BubbleContent
└── Bubble
└── BubbleContentimport {
Bubble,
BubbleContent,
BubbleGroup,
BubbleReactions
} from "~/components/ui/bubble"
export default function BubbleGroupDemo() {
return (
<div class="flex w-full max-w-sm flex-col gap-8 py-12">
<Bubble variant="muted">
<BubbleContent>Can you tell me what's the issue?</BubbleContent>
</Bubble>
<BubbleGroup>
<Bubble align="end">
<BubbleContent>You tell me!</BubbleContent>
</Bubble>
<Bubble align="end">
<BubbleContent>It worked yesterday. You broke it!</BubbleContent>
</Bubble>
<Bubble align="end">
<BubbleContent>Find the bug and fix it.</BubbleContent>
<BubbleReactions aria-label="Reactions: eyes" align="start">
<span>👀</span>
</BubbleReactions>
</Bubble>
</BubbleGroup>
<Bubble variant="muted">
<BubbleContent>
Want me to diff yesterday's you against today's you?
It's a bit embarrassing.
</BubbleContent>
</Bubble>
</div>
)
}Links and Buttons
Use the render prop on BubbleContent to turn a bubble into a link or button.
import { Bubble, BubbleContent, BubbleGroup } from "~/components/ui/bubble"
import { Toaster, createToaster } from "~/components/ui/toast"
export default function BubbleLinkButtonDemo() {
const toast = createToaster()
return (
<div class="flex w-full max-w-sm flex-col gap-8 py-12">
<Bubble variant="muted">
<BubbleContent>How can I help you today?</BubbleContent>
</Bubble>
<Toaster toaster={toast} />
<BubbleGroup>
<Bubble variant="tinted" align="end">
<BubbleContent
render={(partProps) => (
<button
{...partProps}
onClick={() => toast("You clicked forgot password")}
>
I forgot my password
</button>
)}
/>
</Bubble>
<Bubble variant="tinted" align="end">
<BubbleContent
render={(partProps) => (
<button
{...partProps}
onClick={() => toast("You clicked help with subscription")}
>
I need help with my subscription
</button>
)}
/>
</Bubble>
<Bubble variant="tinted" align="end">
<BubbleContent
render={(partProps) => (
<button
{...partProps}
onClick={() =>
toast("You clicked something else. Talk to a human.")
}
>
Something else. Talk to a human.
</button>
)}
/>
</Bubble>
</BubbleGroup>
</div>
)
}Reactions
Use BubbleReactions for bubble reactions. You can use it to display reactions or quick action buttons. Use side and align to position the row — side="top" anchors it to the upper edge. Reactions overlap the bubble edge, so leave vertical space between rows — the examples below use a larger gap for this reason.
import { Bubble, BubbleContent, BubbleReactions } from "~/components/ui/bubble"
import { Button } from "~/components/ui/button"
import { toast } from "~/components/ui/toast"
export default function BubbleReactionsDemo() {
return (
<div class="flex w-full max-w-sm flex-col gap-12 py-12">
<Bubble variant="muted" align="end">
<BubbleContent>
I don't need tests, I know my code works.
</BubbleContent>
<BubbleReactions
align="start"
role="img"
aria-label="Reactions: thumbs up, surprised"
>
<span>👍</span>
<span>😮</span>
</BubbleReactions>
</Bubble>
<Bubble variant="muted">
<BubbleContent>
Bold. Fine I'll add some tests. I'll let you know when
they're done.
</BubbleContent>
<BubbleReactions
role="img"
aria-label="Reactions: eyes, rocket, and 2 more"
>
<span>👀</span>
<span>🚀</span>
<span>+2</span>
</BubbleReactions>
</Bubble>
<Bubble variant="default" align="end">
<BubbleContent>
Tests passed on the first try. All 142 of them. Looking good!
</BubbleContent>
<BubbleReactions
side="top"
align="start"
role="img"
aria-label="Reactions: party popper, clapping hands"
>
<span>🎉</span>
<span>👏</span>
</BubbleReactions>
</Bubble>
<Bubble variant="destructive">
<BubbleContent>Are you sure I can run this command?</BubbleContent>
<BubbleReactions>
<Button
variant="ghost"
size="xs"
onClick={() => toast.success("You clicked yes, running command...")}
>
Yes, run it
</Button>
</BubbleReactions>
</Bubble>
</div>
)
}Show More / Collapsible
Long bubble content can be composed with Collapsible to allow for a show more or show less interaction. Use the CollapsibleTrigger component to trigger the collapsible content.
// Inline SVG icons from Lucide (https://lucide.dev), ISC License, Copyright (c) Lucide Icons and Contributors.
import { createSignal } from "solid-js"
import { Bubble, BubbleContent } from "~/components/ui/bubble"
import { Button } from "~/components/ui/button"
import { Collapsible, CollapsibleTrigger } from "~/components/ui/collapsible"
const text = `The accessibility review found two focus states that were visually too subtle in dark mode.
I checked the dialog, menu, and drawer paths because each one renders focusable controls inside a layered surface.
The dialog and drawer are fine. The menu needs the hover and focus tokens split so keyboard focus stays visible when the pointer is not involved.
I also recommend keeping the change in the style file instead of the primitive so the other themes can choose their own focus treatment later.`
const previewLength = 180
export default function BubbleCollapsible() {
const [open, setOpen] = createSignal(false)
const isLong = text.length > previewLength
const preview = `${text.slice(0, previewLength)}...`
return (
<div class="flex w-full max-w-sm flex-col gap-8 py-12">
<Bubble variant="muted">
<BubbleContent>How can I help you today?</BubbleContent>
</Bubble>
<Bubble variant="muted" align="end">
<BubbleContent class="whitespace-pre-line">
<Collapsible open={open()} onOpenChange={setOpen}>
<div>{open() || !isLong ? text : preview}</div>
{isLong ? (
<CollapsibleTrigger
render={(partProps) => (
<Button
{...partProps}
variant="link"
class="gap-1 p-0 text-muted-foreground"
>
{open() ? "Show less" : "Show more"}
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
data-icon="inline-end"
class="group-data-open/button:rotate-180"
>
<path d="m6 9 6 6 6-6" />
</svg>
</Button>
)}
/>
) : null}
</Collapsible>
</BubbleContent>
</Bubble>
</div>
)
}Tooltip
Wrap a bubble in a Tooltip to reveal metadata on hover, such as when a message was read.
// Inline SVG icons from Lucide (https://lucide.dev), ISC License, Copyright (c) Lucide Icons and Contributors.
import { Bubble, BubbleContent, BubbleReactions } from "~/components/ui/bubble"
import { Button } from "~/components/ui/button"
import { Tooltip, TooltipContent, TooltipTrigger } from "~/components/ui/tooltip"
export default function BubbleTooltipDemo() {
return (
<div class="flex w-full max-w-sm flex-col gap-4 py-12">
<Bubble variant="secondary">
<BubbleContent>Did you remove the stale route?</BubbleContent>
</Bubble>
<Bubble align="end">
<BubbleContent>Yes, removed it from the registry.</BubbleContent>
<BubbleReactions class="p-0">
<Tooltip>
<TooltipTrigger
render={(partProps) => (
<Button {...partProps} variant="ghost" size="icon-xs">
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="M20 6 9 17l-5-5" />
</svg>
</Button>
)}
/>
<TooltipContent>Read on Jan 5, 2026 at 4:32 PM</TooltipContent>
</Tooltip>
</BubbleReactions>
</Bubble>
</div>
)
}Popover
Pair a bubble with a Popover to surface more information on demand, such as the full error message for a failed action.
// Inline SVG icons from Lucide (https://lucide.dev), ISC License, Copyright (c) Lucide Icons and Contributors.
import { Bubble, BubbleContent, BubbleReactions } from "~/components/ui/bubble"
import { Button } from "~/components/ui/button"
import {
Popover,
PopoverContent,
PopoverDescription,
PopoverHeader,
PopoverTitle,
PopoverTrigger
} from "~/components/ui/popover"
export default function BubblePopoverDemo() {
return (
<div class="flex w-full max-w-sm flex-col gap-4 py-12">
<Bubble align="end">
<BubbleContent>Run the build script.</BubbleContent>
</Bubble>
<Bubble variant="destructive">
<BubbleContent>Failed to run the command.</BubbleContent>
<BubbleReactions>
<Popover>
<PopoverTrigger
render={(partProps) => (
<Button
{...partProps}
variant="ghost"
size="icon-xs"
aria-label="Show error details"
class="aria-expanded:text-destructive"
>
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<circle cx="12" cy="12" r="10" />
<path d="M12 16v-4" />
<path d="M12 8h.01" />
</svg>
</Button>
)}
/>
<PopoverContent>
<PopoverHeader>
<PopoverTitle class="text-sm">
Command failed with exit code 1
</PopoverTitle>
<PopoverDescription class="text-sm">
ENOENT: no such file or directory, open pnpm-lock.yaml
</PopoverDescription>
</PopoverHeader>
</PopoverContent>
</Popover>
</BubbleReactions>
</Bubble>
</div>
)
}Accessibility
Bubble renders the presentational message surface. Keep conversation-level semantics on the surrounding container and follow the guidelines below.
Labeling Reactions
Reactions render as a row of emoji. A screen reader reads each glyph with no context, and counters like +8 are announced as “plus eight”. Group the row as a single image with a descriptive aria-label so it announces once. role="img" also hides the individual emoji from assistive tech, so no aria-hidden is needed.
When reactions are interactive, render buttons instead and give icon-only buttons an aria-label.
Interactive Bubbles
When a bubble is clickable, render it as a real <button> or <a> with the render prop so it is focusable and exposes the correct role. BubbleContent ships a visible focus ring for interactive elements, and the accessible name comes from the bubble text. No extra label is needed.
Meaning Beyond Color
Bubble variants signal role and tone with color. Pair them with text, alignment, or icons so meaning is not conveyed by color alone. For a destructive bubble, keep the error context in the message text rather than relying on the color treatment.
API Reference
Bubble
The root bubble wrapper.
BubbleContent
The bubble content wrapper.
BubbleReactions
Displays overlapped reactions for a bubble.
BubbleGroup
Groups consecutive bubbles from the same sender.