Live Examples

Chat Interface with Messages

JD

John Doe

Online

JD
Hi there! How can I help you today?
10:30 AM
I need help with my account setup
10:31 AM
JD
Sure! I'd be happy to help. What specific issue are you facing?
10:32 AM
I'm having trouble resetting my password
10:33 AM

HTML Structure

<div class="demo">
				<div >
				<div >
				<div class="avatar">JD</div>
				<div class="info">
				<h3>John Doe</h3>
				<p class="status">Online</p>
				</div>
				</div>
				</div>

				<div >
				<div class="message">
				<div class="avatar">JD</div>
				<div>
				<div class="bubble received">Message text</div>
				</div>
				</div>

				<div class="message">
				<div>
				<div class="bubble sent">Your message</div>
				</div>
				</div>
				</div>

				<div class="inputarea">
				<input type="text" class="input" placeholder="Type a message...">
				<button class="send">Send</button>
				</div>
				</div>

Features

  • Message Display - Received and sent messages with different styling
  • User Avatars - Profile pictures or initials
  • Message Timestamps - Time indication for each message
  • Auto Scroll - Messages scroll to bottom automatically
  • Online Status - Shows user availability
  • Message Input - Textarea for composing messages

Message Types

  • User Messages - Messages sent by current user (right-aligned, primary color)
  • Received Messages - Messages from other users (left-aligned, neutral color)
  • System Messages - Status updates or notifications (centered, muted)
  • Timestamps - Time indication for each message
  • Read Receipts - Indicators showing message status
  • Typing Indicator - Show when user is typing

Use Cases

  • Live Chat Support - Customer service and support tickets
  • Team Messaging - Internal communication and collaboration
  • Peer-to-Peer Chat - Direct messaging between users
  • Chatbots - AI assistant conversations
  • Group Chat - Multiple participants in single conversation
  • Notifications - In-app messaging and alerts

Accessibility

  • Use semantic HTML for message structure
  • Include aria-label on input fields
  • Provide high contrast between message styles
  • Use role="region" for message area for screen readers
  • Support keyboard navigation (Tab, Enter to send)
  • Announce new messages to screen readers (ARIA live regions)

Responsive Behavior

This component automatically adapts to different screen sizes:

Mobile (< 768px)

On mobile devices:

  • Optimized for small screens
  • Touch-friendly spacing maintained (44px minimum)
  • Text wraps naturally without overflow
  • Content density optimized for readability

Desktop (1024px+)

On desktop displays:

  • Enhanced visual features
  • Hover states and transitions
  • Full keyboard navigation support
  • Optimal spacing and sizing

Framework Integration

Responsive behavior is automatic:
  • Framework handles media queries
  • No custom CSS required
  • Mobile-first approach applied
  • Accessibility maintained at all sizes

Best Practices

  • Auto Scroll - Always scroll to latest message
  • Clear Input - Empty input after sending
  • Timestamps - Show time for context
  • Avatars - Consistent user identification
  • Read States - Indicate message delivery status
  • Typing Indicator - Show when other user is typing