Building a Chatbot from Scratch: Part 5 - Styling
Our chatbot works. Now let's make it look professional with modern CSS.
Series Recap
- [Part 1](/blog/building-chatbot-from-scratch-part-1-setup): Project setup
- [Part 2](/blog/building-chatbot-from-scratch-part-2-ui): Chat UI
- [Part 3](/blog/building-chatbot-part-3-websockets): WebSockets
- [Part 4](/blog/building-chatbot-part-4-adding-intelligence): Response logic
Time to make it pretty.
The Design
We're going for:
- Clean, modern chat interface
- User messages on the right
- Bot messages on the left
- Typing indicator
- Smooth animations
Base Styles
:root {
--bg-primary: #1a1a2e;
--bg-secondary: #16213e;
--accent: #0f3460;
--text: #e4e4e7;
--user-bubble: #3b82f6;
--bot-bubble: #374151;
}
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
background: var(--bg-primary);
color: var(--text);
}
Chat Container
.chat-container {
max-width: 500px;
height: 100vh;
margin: 0 auto;
display: flex;
flex-direction: column;
background: var(--bg-secondary);
}
.chat-header {
padding: 1rem;
background: var(--accent);
display: flex;
align-items: center;
gap: 0.75rem;
}
.chat-header .avatar {
width: 40px;
height: 40px;
border-radius: 50%;
background: var(--user-bubble);
display: flex;
align-items: center;
justify-content: center;
}
.chat-header .status {
font-size: 0.875rem;
opacity: 0.7;
}
Messages Area
.messages {
flex: 1;
overflow-y: auto;
padding: 1rem;
display: flex;
flex-direction: column;
gap: 0.75rem;
}
.message {
max-width: 80%;
padding: 0.75rem 1rem;
border-radius: 1rem;
animation: fadeIn 0.2s ease;
}
.message.user {
align-self: flex-end;
background: var(--user-bubble);
border-bottom-right-radius: 0.25rem;
}
.message.bot {
align-self: flex-start;
background: var(--bot-bubble);
border-bottom-left-radius: 0.25rem;
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
Input Area
.input-area {
padding: 1rem;
background: var(--accent);
display: flex;
gap: 0.5rem;
}
.input-area input {
flex: 1;
padding: 0.75rem 1rem;
border: none;
border-radius: 1.5rem;
background: var(--bg-secondary);
color: var(--text);
font-size: 1rem;
}
.input-area input:focus {
outline: 2px solid var(--user-bubble);
}
.input-area button {
padding: 0.75rem 1.25rem;
border: none;
border-radius: 1.5rem;
background: var(--user-bubble);
color: white;
cursor: pointer;
transition: opacity 0.2s;
}
.input-area button:hover {
opacity: 0.9;
}
Typing Indicator
.typing-indicator {
display: flex;
gap: 4px;
padding: 0.75rem 1rem;
background: var(--bot-bubble);
border-radius: 1rem;
width: fit-content;
}
.typing-indicator span {
width: 8px;
height: 8px;
background: var(--text);
border-radius: 50%;
animation: bounce 1.4s infinite ease-in-out;
}
.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
0%, 80%, 100% { transform: translateY(0); }
40% { transform: translateY(-6px); }
}
The Result
A professional-looking chat interface with:
- Dark mode aesthetic
- Smooth animations
- Clear visual hierarchy
- Responsive design
What's Next
In the final part, we'll deploy our chatbot and make it accessible to the world.
Full code: github.com/chrishacia/simple-chatbot