File: usage.md | Updated: 11/15/2025
Slash Forward
Docs Cookbook Providers Playground AI ElementsAI ElementsLeft sparkleRight sparkle AI GatewayGateway
Search...⌘KFeedback GitHub Vercel LogoSign in with Vercel
Learn how to use AI Elements components in your application.
Once an AI Elements component is installed, you can import it and use it in your application like any other React component. The components are added as part of your codebase (not hidden in a library), so the usage feels very natural.
After installing AI Elements components, you can use them in your application like any other React component. For example:
conversation.tsx
'use client';
import {
Message,
MessageContent,
MessageResponse,
} from '@/components/ai-elements/message';
import { useChat } from '@ai-sdk/react';
const Example = () => {
const { messages } = useChat();
return (
<>
{messages.map(({ role, parts }, index) => (
<Message from={role} key={index}>
<MessageContent>
{parts.map((part, i) => {
switch (part.type) {
case 'text':
return <MessageResponse key={`${role}-${i}`}>{part.text}</MessageResponse>;
}
})}
</MessageContent>
</Message>
))}
</>
);
};
export default Example;
In the example above, we import the Message component from our AI Elements directory and include it in our JSX. Then, we compose the component with the MessageContent and MessageResponse subcomponents. You can style or configure the component just as you would if you wrote it yourself – since the code lives in your project, you can even open the component file to see how it works or make custom modifications.
All AI Elements components take as many primitive attributes as possible. For example, the Message component extends HTMLAttributes<HTMLDivElement>, so you can pass any props that a div supports. This makes it easy to extend the component with your own styles or functionality.
If you re-install AI Elements by rerunning npx ai-elements@latest, the CLI will ask before overwriting the file so you can save any custom changes you made.
After installation, no additional setup is needed. The component’s styles (Tailwind CSS classes) and scripts are already integrated. You can start interacting with the component in your app immediately.
For example, if you'd like to remove the rounding on Message, you can go to components/ai-elements/message.tsx and remove rounded-lg as follows:
components/ai-elements/message.tsx
export const MessageContent = ({
children,
className,
...props
}: MessageContentProps) => (
<div
className={cn(
'flex flex-col gap-2 text-sm text-foreground',
'group-[.is-user]:bg-primary group-[.is-user]:text-primary-foreground group-[.is-user]:px-4 group-[.is-user]:py-3',
className,
)}
{...props}
>
<div className="is-user:dark">{children}</div>
</div>
);
Introduction
What is AI Elements and why you should use it.
Troubleshooting
What to do if you run into issues with AI Elements.
On this page
Example Extensibility Customization
GitHubEdit this page on GitHub Scroll to topCopy pageOpen in chat