---
title: "Message Bubble | Free React & Tailwind Agents Component | Motion UI"
canonical: "https://blacknest.dev/motion/c/agents/message-bubble"
github_source: "https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/message-bubble.tsx"
install_command: "npx motion-ui-skill add message-bubble"
dependencies: ["clsx","lucide-react","motion","react","react-dom","tailwind-merge"]
category: "agents"
subcategory: "agents"
---

# Message Bubble

> A focused conversational surface with visual tones, independent alignment, grouped messages, expandable content, and interactive link or button support.

## Install

```bash
npx motion-ui-skill add message-bubble
```

## Dependencies

- `clsx`
- `lucide-react`
- `motion`
- `react`
- `react-dom`
- `tailwind-merge`

## Usage

### Animated Surfaces usage

An interactive conversation where each newly sent user row pops up once while the assistant streams into a stable row.

```tsx
"use client";

import { ChatPreview } from "@/components/previews/agents/chat-preview";

export function MessageBubblePreview() {
  return (
    <ChatPreview
      reply="That message mounted once with a spring pop. Streaming updates only change its content, so the entrance does not replay."
      placeholder="Send a bubble…"
    />
  );
}
```

### With Avatars usage

Progressively arriving messages with sender avatars, metadata, delivery state, and grouped follow-up alignment.

```tsx
"use client";

import { Bot, RotateCcw, User } from "lucide-react";
import { AnimatePresence } from "motion/react";
import { useCallback, useEffect, useRef, useState } from "react";
import {
  MessageBubble,
  MessageBubbleContent,
} from "@/components/agents/message-bubble";
import {
  Message,
  MessageAvatar,
  MessageContent,
  MessageFooter,
  MessageGroup,
  MessageHeader,
} from "@/components/agents/message";
import { StreamingResponse } from "@/components/agents/streaming-response";

export function MessageBubbleAvatarsPreview() {
  const timer = useRef<number | undefined>(undefined);
  const [run, setRun] = useState(0);
  const [step, setStep] = useState(0);

  const replay = useCallback(() => {
    if (timer.current) window.clearTimeout(timer.current);
    setStep(0);
    setRun((value) => value + 1);
  }, []);

  useEffect(() => {
    if (step >= 2) return;
    timer.current = window.setTimeout(
      () => setStep((value) => value + 1),
      step === 0 ? 650 : 900,
    );
    return () => {
      if (timer.current) window.clearTimeout(timer.current);
    };
  }, [step]);

  return (
    <div className="flex h-[410px] w-full max-w-xl flex-col justify-center px-3">
      <MessageGroup key={run} spacing="default">
        <Message from="user">
          <MessageAvatar className="bg-foreground text-background">
            <User />
          </MessageAvatar>
          <MessageContent>
            <MessageHeader>
              <span className="font-medium text-foreground/70">You</span>
              <span>Now</span>
            </MessageHeader>
            <MessageBubble variant="solid">
              <MessageBubbleContent>
                Can you turn these notes into a launch update?
              </MessageBubbleContent>
            </MessageBubble>
            <MessageFooter>Delivered</MessageFooter>
          </MessageContent>
        </Message>

        <AnimatePresence mode="popLayout">
          {step >= 1 ? (
            <Message key="draft" from="assistant">
              <MessageAvatar>
                <Bot />
              </MessageAvatar>
              <MessageContent>
                <MessageHeader>
                  <span className="font-medium text-foreground/70">Assistant</span>
                  <span>Just now</span>
                </MessageHeader>
                <MessageBubble variant="soft">
                  <MessageBubbleContent>
                    <StreamingResponse status="complete" showActions={false}>
                      Absolutely. I’ll keep it concise and lead with what changed.
                    </StreamingResponse>
                  </MessageBubbleContent>
                </MessageBubble>
              </MessageContent>
            </Message>
          ) : null}

          {step >= 2 ? (
            <Message key="follow-up" from="assistant">
              <MessageAvatar placeholder />
              <MessageContent>
                <MessageBubble variant="soft">
                  <MessageBubbleContent>
                    <StreamingResponse status="complete" showActions={false}>
                      Do you want the tone to feel more technical or more customer-facing?
                    </StreamingResponse>
                  </MessageBubbleContent>
                </MessageBubble>
              </MessageContent>
            </Message>
          ) : null}
        </AnimatePresence>
      </MessageGroup>

      <div className="flex h-11 items-end justify-center">
        <button
          type="button"
          onClick={replay}
          className="inline-flex h-8 items-center gap-1.5 rounded-full border border-border px-3 text-xs font-medium text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring"
        >
          <RotateCcw className="size-3.5" />
          Replay
        </button>
      </div>
    </div>
  );
}
```

### Show More usage

A long assistant message with a compact line-clamped preview and animated disclosure control.

```tsx
"use client";

import { Bot } from "lucide-react";
import {
  MessageBubble,
  MessageBubbleCollapsible,
  MessageBubbleContent,
} from "@/components/agents/message-bubble";
import {
  Message,
  MessageAvatar,
  MessageContent,
  MessageHeader,
} from "@/components/agents/message";
import { StreamingResponse } from "@/components/agents/streaming-response";

export function MessageBubbleCollapsiblePreview() {
  return (
    <div className="flex h-[410px] w-full max-w-xl items-start px-3 pt-14">
      <Message from="assistant">
        <MessageAvatar>
          <Bot />
        </MessageAvatar>
        <MessageContent>
          <MessageHeader>
            <span className="font-medium text-foreground/70">Assistant</span>
            <span>Summary</span>
          </MessageHeader>
          <MessageBubble variant="soft" animateIn={false}>
            <MessageBubbleContent className="max-w-[90%]">
              <StreamingResponse status="complete" showActions={false}>
                <MessageBubbleCollapsible collapsedLines={4}>
                  <p>
                    The release is ready for a focused rollout. The main conversation flow,
                    keyboard navigation, error recovery, and reduced-motion behavior are all
                    covered.
                  </p>
                  <p>
                    I would keep advanced workflow controls out of this version. They add
                    configuration without improving the first-run experience, and the usage
                    data from this release will give us a better basis for those decisions.
                  </p>
                  <p>
                    Before publishing, run the accessibility suite once more and verify the
                    streaming behavior with a long response on a smaller viewport.
                  </p>
                </MessageBubbleCollapsible>
              </StreamingResponse>
            </MessageBubbleContent>
          </MessageBubble>
        </MessageContent>
      </Message>
    </div>
  );
}
```

## API Reference

### MessageBubble

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `variant` | `"outline" \| "solid" \| "danger" \| "ghost" \| "soft" \| "tint"` | `soft` | No | — |
| `align` | `"end" \| "start"` | — | No | Defaults to the surrounding Message alignment when omitted. |
| `animateIn` | `boolean` | `false` | No | Plays the bubble entrance once when this component mounts. |
| `className` | `string` | — | No | — |

### MessageBubbleContent

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `render` | `ReactElement<unknown, string \| JSXElementConstructor<any>>` | — | No | Replaces the content element while preserving bubble styling. |
| `className` | `string` | — | No | — |

### MessageBubbleGroup

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `spacing` | `"default" \| "compact"` | `compact` | No | — |
| `className` | `string` | — | No | — |

### MessageBubbleCollapsible

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `open` | `boolean` | — | No | — |
| `defaultOpen` | `boolean` | `false` | No | — |
| `onOpenChange` | `((open: boolean) => void)` | — | No | — |
| `collapsedLines` | `2 \| 3 \| 4 \| 5 \| 6` | `4` | No | — |
| `moreLabel` | `ReactNode` | `Show more` | No | — |
| `lessLabel` | `ReactNode` | `Show less` | No | — |
| `contentClassName` | `string` | — | No | — |
| `triggerClassName` | `string` | — | No | — |
| `className` | `string` | — | No | — |

## Source Files

- [components/agents/message-bubble.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/message-bubble.tsx)
- [components/agents/agent-disclosure.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/agent-disclosure.tsx)
- [components/agents/citations.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/citations.tsx)
- [components/agents/message-context.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/message-context.tsx)
- [components/agents/message-scroller.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/message-scroller.tsx)
- [components/agents/message.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/message.tsx)
- [components/agents/prompt-input.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/prompt-input.tsx)
- [components/agents/streaming-response.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/streaming-response.tsx)
- [components/motion/button/base.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/button/base.tsx)
- [components/motion/button/index.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/button/index.tsx)
- [components/motion/button/magnetic.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/button/magnetic.tsx)
- [components/motion/button/metallic.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/button/metallic.tsx)
- [components/motion/button/stateful.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/button/stateful.tsx)
- [components/motion/magnetic.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/magnetic.tsx)
- [components/motion/popover-morph.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/popover-morph.tsx)
- [components/motion/popover-position.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/popover-position.ts)
- [components/motion/preview-rail.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/preview-rail.tsx)
- [components/motion/select.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/select.tsx)
- [components/previews/agents/chat-preview.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/previews/agents/chat-preview.tsx)
- [lib/ease.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/ease.ts)
- [lib/favicon.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/favicon.ts)
- [lib/hooks/use-dismiss.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/hooks/use-dismiss.ts)
- [lib/hooks/use-favicon.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/hooks/use-favicon.ts)
- [lib/hooks/use-hover-capable.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/hooks/use-hover-capable.ts)
- [lib/hooks/use-hover-gesture.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/hooks/use-hover-gesture.ts)
- [lib/hooks/use-tap-gesture.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/hooks/use-tap-gesture.ts)
- [lib/portal.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/portal.tsx)
- [lib/touch.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/touch.ts)
- [lib/utils.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/utils.ts)
