Build a Real-Time Chat Application with Node.js
Lesson 5 of 10 50% of course

Frontend CSS — Modern Chat UI Design

1 · 5 min · 6/7/2026

Learn Frontend CSS — Modern Chat UI Design in our free Build a Real-Time Chat Application with Node.js series. Step-by-step explanations, examples, and interview tips on Toolliyo Academy.

Sign in to track progress and bookmarks.

Frontend CSS — Modern Chat UI Design
Lesson 5 of 10 · Part 2 — Build the App · Build a Real-Time Chat Application with Node.js
Course: Build a Real-Time Chat Application with Node.js · Lesson: 5/10 · Read time: ~20 min · Level: Beginner

Frontend CSS — Modern Chat UI Design

CSS controls colors, spacing, layout, and responsiveness. We use a dark theme inspired by WhatsApp Web and Telegram — blue bubbles for your messages, gray for others, sticky input bar at the bottom.

Create public/style.css with the complete stylesheet below.

Full style.css

:root {
  --bg: #0f172a;
  --card: #1e293b;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --bubble-other: #334155;
  --bubble-mine: #2563eb;
  --system: #64748b;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

/* ——— Login ——— */
.login-card {
  background: var(--card);
  padding: 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 400px;
}

.login-card h1 { margin-bottom: 0.25rem; font-size: 1.75rem; }
.subtitle { color: var(--muted); margin-bottom: 1.5rem; font-size: 0.95rem; }

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
  margin-top: 1rem;
}

input[type="text"] {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid #475569;
  border-radius: 8px;
  background: #0f172a;
  color: var(--text);
  font-size: 1rem;
}

input:focus {
  outline: 2px solid var(--primary);
  border-color: transparent;
}

#join-btn {
  width: 100%;
  margin-top: 1.5rem;
  padding: 0.85rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

#join-btn:hover { background: var(--primary-dark); }

.error { color: var(--danger); font-size: 0.85rem; margin-top: 0.75rem; }

/* ——— Chat layout ——— */
#chat-screen {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  max-width: 900px;
  margin: 0 auto;
  padding: 0;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: var(--card);
  border-bottom: 1px solid #334155;
  position: sticky;
  top: 0;
  z-index: 10;
}

#room-title { font-size: 1.1rem; }
.typing { font-size: 0.8rem; color: var(--muted); font-style: italic; }

.online-users {
  font-size: 0.8rem;
  color: var(--muted);
  text-align: right;
  max-width: 180px;
}

.online-users strong { color: var(--text); display: block; margin-bottom: 0.25rem; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem 6rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: calc(100vh - 130px);
}

.message-row { display: flex; flex-direction: column; max-width: 75%; }
.message-row.mine { align-self: flex-end; align-items: flex-end; }
.message-row.other { align-self: flex-start; align-items: flex-start; }
.message-row.system { align-self: center; max-width: 100%; }

.bubble {
  padding: 0.65rem 1rem;
  border-radius: 16px;
  line-height: 1.45;
  word-break: break-word;
}

.message-row.mine .bubble { background: var(--bubble-mine); border-bottom-right-radius: 4px; }
.message-row.other .bubble { background: var(--bubble-other); border-bottom-left-radius: 4px; }
.message-row.system .bubble {
  background: transparent;
  color: var(--system);
  font-size: 0.85rem;
  font-style: italic;
  padding: 0.25rem;
}

.meta {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.2rem;
}

.time {
  font-size: 0.68rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.chat-input-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--card);
  border-top: 1px solid #334155;
  max-width: 900px;
  margin: 0 auto;
}

#message-input { flex: 1; }

#send-btn {
  padding: 0.75rem 1.25rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

@media (max-width: 600px) {
  .message-row { max-width: 90%; }
  .online-users { max-width: 120px; font-size: 0.72rem; }
}

Key design decisions explained

CSS variables (:root)

We define colors once at the top:

--primary: #3b82f6;      /* Blue — your message bubbles */
--bubble-other: #334155; /* Gray — other people's messages */
--bg: #0f172a;           /* Dark page background */

Change the theme site-wide by editing variables only — no hunting through 200 lines.

💡 Tip: CSS variables work in all modern browsers. They are one of the best habits for maintainable UI code.

Login card — centered layout

.screen uses flexbox to center the login card vertically and horizontally. max-width: 400px keeps inputs readable on large monitors.

Chat bubbles — left vs right

JavaScript adds classes mine or other to each message row:

  • .message-row.minealign-self: flex-end pushes bubble to the right
  • .message-row.other — aligned left
  • .message-row.system — centered italic gray text for “Alex joined”

Scrollable messages + sticky input

.messages has overflow-y: auto so long chats scroll. The input bar uses position: fixed; bottom: 0 so it never scrolls away — like every modern chat app.

⚠️ Common Mistake: Forgetting bottom padding on .messages (padding-bottom: 6rem). Without it, the last messages hide behind the fixed input bar.

Mobile responsive (@media)

On screens under 600px, bubbles use 90% width instead of 75% — easier to read on phones.

👨‍🏫 Teaching note: Demo the UI in browser DevTools mobile view (F12 → toggle device toolbar). Students enjoy seeing their app “work on iPhone” without owning one.

Visual checklist after saving CSS

  • ✅ Dark background, light text
  • ✅ Login form centered with rounded card
  • ✅ Blue primary button with hover state
  • ✅ Chat layout ready for bubbles (even before JS works)

Next: wire up JavaScript so messages actually flow.

Continue learning

Previous: Frontend HTML — Login Screen & Chat Layout

Next: Frontend JavaScript — Connect & Send Messages

Course home: All 10 lessons

Test your knowledge

Quizzes linked to this course—pass to earn certificates.

Browse all quizzes
Build a Real-Time Chat Application with Node.js

On this page

Full style.css Key design decisions explained CSS variables (:root) Login card — centered layout Chat bubbles — left vs right Scrollable messages + sticky input Mobile responsive (@media) Visual checklist after saving CSS Continue learning
Part 1 — Getting Started
Introduction — What We Are Building Project Setup — Folder, npm & Dependencies
Part 2 — Build the App
Building the Server — Express & Socket.IO Frontend HTML — Login Screen & Chat Layout Frontend CSS — Modern Chat UI Design Frontend JavaScript — Connect & Send Messages
Part 3 — Run, Learn & Extend
Running the App & Testing in Two Tabs How Socket.IO Works — Deep Dive
Part 4 — Ship It
Bonus Features — Typing, Online Users & Timestamps Deploy to Railway, Troubleshooting & Summary
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details