Remember all that custom UI code we just wrote? The manual state management, the scroll behavior, the message formatting? Professional chat interfaces like ChatGPT, Claude, and Cursor use sophisticated component systems to handle these complexities.
AI Elements gives you that same power - let's transform your basic chat into something production-ready.
The AI SDK team has built Elements - a comprehensive component library specifically designed for AI applications. It's built on top of shadcn/ui and provides everything you need out of the box.
What are AI SDK Elements?
Elements is a collection of 20+ production-ready React components designed specifically for AI interfaces. These components are tightly integrated with AI SDK hooks like
useChat, handling the unique challenges of streaming responses, tool displays, and markdown rendering that standard React components don't address.Unlike regular UI libraries, Elements understands AI-specific patterns - message parts, streaming states, tool calls, and reasoning displays - making it the perfect companion to the AI SDK.
Let's transform our chatbot with a single command:
bash
When prompted, press Enter to confirm the installation path, and select Yes when asked about overwriting existing components.
What happens during installation?
After installation, check out what you now have in components/ai-elements/:
First, we need to import all the Elements components we'll be using. Add these imports at the top of your app/(5-chatbot)/chat/page.tsx file, right after your existing imports:
typescript
With the imports ready, we can now progressively replace each part of the UI.
Now let's replace how messages are displayed using Elements' Message component.
Update just the message rendering part (around line 12-20):
typescript

Save and test. You'll see proper message bubbles instead of "User:" and "AI:" labels! But we still have the scrolling issues and basic input.
Now let's wrap everything in the Conversation component which handles auto-scrolling.
Wrap your messages in the Conversation components (you already have the imports from Step 1):
jsx
Test again with a more complex prompt - now messages stay in view and the view scrolls as they stream in! Plus you get a nice empty state.
The text input is poorly formatted and needs to be updated too.
Finally, let's replace the basic input with Elements' smart input components.
Update the status handling (you already have the imports from Step 1):
typescript
Replace your form with the PromptInput components:
jsx
Save your changes and test the chatbot:
bash
Navigate to http://localhost:3000/chat and try it out. After these incremental improvements, you'll notice:
Four Steps Complete
We've incrementally replaced our custom UI with Elements components:
- Added all the necessary imports upfront
- Upgraded just the message display
- Added smart scrolling with Conversation container
- Upgraded the input with PromptInput
The interface looks professional, but markdown isn't rendering yet. Let's fix that next!
The messages look better, but markdown isn't rendering. Elements includes a Response component that handles markdown beautifully. Let's use it for AI messages:
jsx
Refresh your browser and ask the AI to write code again. Try: "give me a react app that uses the ai sdk to build a chat"

BOOM! Look at the transformation:
code appears formattedWith just one component change, you've transformed raw markdown text into beautifully formatted content!
Performance Note
The
Responsecomponent is optimized for streaming - it efficiently handles incremental markdown updates without re-parsing the entire content on each stream chunk. This is crucial for maintaining smooth performance during AI responses.
Here's the final version with both improvements:
typescript
Look at what we accomplished in two simple steps:
Before (Custom UI)
After (Elements)
You've installed 20+ components with Elements. While we're focusing on the chat basics now, here's what else you have available:
Don't worry about implementing these now - we'll explore tool usage in the upcoming lessons where you'll see these components in action.
You've just experienced firsthand why component libraries exist. Elements didn't just save you time - it provided:
Now that we have a solid foundation with Elements, we can focus on what really matters - the AI functionality. In the next lessons, we'll explore:
All using the professional components from Elements!
Setup Checklist
Explore More Elements Components
Elements includes 20+ components beyond what we've used:
- Suggestions - Quick prompts below the input
- Loader - Custom loading indicators for streaming
- ChainOfThought - Visualize reasoning steps
- Branch - Enable conversation forking
- TypingIndicator - Show when AI is responding
Browse
components/ai-elements/to discover more components and enhance your chat interface!
Mark this chapter as finished to continue
Mark this chapter as finished to continue