Keyframery

Markdown

Renders an AI answer's markdown as it streams: finished blocks stay put while only the last one grows, each new block rises in, unfinished syntax reads as it will once closed, and a slim caret marks where the text is arriving.

See it as an AI agent does.

Resize preview. Focus the handle and use the left or right arrow keys. Hold Shift for larger steps.— px
Customize1 controls
Animation speed1×

Installation

npx shadcn@latest add @keyframery/markdown

This adds components/keyframery/markdown.tsx and its primitive to your project, and installs UI SDK, along with agent-content, code-block, which it builds on. The motion tokens are added to your global CSS the first time you install a component.

Usage

import { Markdown } from "@/components/keyframery/markdown"

export default function Usage() {
  return <Markdown>{"Your table for two is booked for **Saturday at 19:30**."}</Markdown>
}

Examples

Streaming

Pass the text as it arrives and set streaming until it ends. Finished blocks stay exactly where they are, an unclosed ** or fence reads as it will once closed, and a caret marks the end.

Code and tables

Fenced code is Keyframery's code block, with its language and a copy button. Tables scroll sideways on a narrow screen and take their column alignment from the divider row.

Your own elements

components swaps any element by its tag name, and codeBlock replaces fenced code. Each gets the element's props, including its data-slot, so the styles still reach it. Keep the object outside render.

Motion

MoveWhat you see
SteadyEach block is drawn from its own source, so finished blocks never re-render or move while the text after them arrives.
RiseA new block fades up out of a soft blur as it starts.
CaretWhile streaming, a slim caret sits at the end of the text and pulses softly; it stays still for reduced motion.
CascadeFenced code arrives line by line in Keyframery's code block, and its copy key appears when the closing fence lands.

Timing and springiness follow the motion style you set. To change how fast this markdown moves, pass speed:

<Markdown speed="fast">
  …
</Markdown>

"fast" is 0.6×, "slow" 1.4×, and a number sets the multiplier. With reduced motion turned on, nothing moves: changes happen at once or with a short fade.

Theming

Set these CSS variables on the component or a parent. Leave them unset to follow the light and dark theme. The open Customize panel below the preview lets you try these settings.

VariableWhat it changesDefault
--markdown-inkBody texttext-foreground
--markdown-mutedQuotes, list markers and table headerstext-muted-foreground
--markdown-linkLinkstext-foreground
--markdown-caretCaretbg-foreground
--markdown-code-faceInline code surfacebg-muted
--markdown-fontBody sizetext-[14px]
--markdown-gapBlock spacinggap-3

API reference

Every part takes className and children, along with the props of the element it renders. The parts are rendered by UI SDK, so they also take render, to draw your own element, and a function of their state for className and style.

Markdown

Renders a <div>, and takes its props too.

Prop

Type

MarkdownCodeBlock

Prop

Type

Other parts

These take the props of the element they render, and nothing else:

  • MarkdownCaret: a <span>

Keyboard

KeyWhat it does
TabMoves to the next link, then to a code block's code and its copy button.
EnterOpens the focused link. Links to other sites open in a new tab.

Accessibility

Roles, keyboard and focus are declared on the component's UI SDK primitive, and state is announced through the matching ARIA attributes. More in Accessibility.

Built on UI SDK's core

UI SDK doesn't ship a markdown, so this one is defined with its core: one definePrimitive in components/keyframery/core/markdown-core.ts, with no React in it. UI SDK's adapters can render that same definition in Vue, Svelte, Solid and web components. To keep your own styling and take only the motion, import from @/components/keyframery/primitives/markdown.

Questions

How does the animated Markdown for UI SDK move?

Steady: Each block is drawn from its own source, so finished blocks never re-render or move while the text after them arrives. Rise: A new block fades up out of a soft blur as it starts. Caret: While streaming, a slim caret sits at the end of the text and pulses softly; it stays still for reduced motion. Cascade: Fenced code arrives line by line in Keyframery's code block, and its copy key appears when the closing fence lands.

Do I need Motion or Framer Motion for the animated Markdown?

No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.

UI SDK has no markdown. How is this one built on UI SDK?

Its behaviour is one definition written with UI SDK's core (definePrimitive), in components/keyframery/core/markdown-core.ts. Its parts are rendered by UI SDK's adapter, so they take render, state-based class names and data-slot, like every UI SDK component.

What happens to the Markdown when someone turns on reduced motion?

Nothing moves. State changes happen at once, or with a short fade.

All components

On this page