Messages UI CSS for Web
A CSS stylesheet for presenting conversations on the web, with bubbles, timestamps, and spacing that make each exchange easy to follow.
Documentation
Explore the elements of the conversation interface and how they work.
Stylesheet and Examples
Add the Stylesheet and choose the classes you need to present a conversation on your page.
Interface Elements
Bubbles, emoji, and timestamps give a conversation its structure and rhythm.
1. Bubbles
Bubbles can contain text, images, or both. Blue bubbles align right and gray bubbles align left. Group consecutive messages by adding a tail only to the last bubble.
2. Emoji
Display emoji on their own at a larger size. Use up to three per message; place longer sequences in a bubble.
3. Timestamps
Center a date, time, or status within the conversation.
4. Spacing
Use tighter spacing to group consecutive messages and wider spacing to indicate a change in time or sender. Set the spacing by choosing the appropriate classes.
5. Gradient
Blue bubbles use a viewport-based gradient, so their color changes as the page scrolls. At viewport widths of 1024 pixels or less, they use a solid color.
6. Width
The conversation is capped at 680 pixels, and bubbles at 70% of its width, keeping the two sides easy to distinguish.
Using the Stylesheet
Add the stylesheet, then apply the appropriate classes to your HTML.
1. Add the Stylesheet
Add the stylesheet inside the HTML <head>.
<link rel="stylesheet" type="text/css" href="https://media.chiawei.com/web/msgsk/v1/messages.css">
Include the stylesheet only on pages that display conversations.
2. Add Your HTML
Place the conversation in a .chat container and apply the appropriate classes to each message:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="https://media.chiawei.com/web/msgsk/v1/messages.css">
</head>
<body>
<div class="chat">
<div class="msg sent last">...</div>
<div class="msg received last">...</div>
</div>
</body>
</html>
CSS Classes
Choose the classes that match each message’s content and direction.
.chat
The conversation container.
.msg.sent
A right-aligned blue bubble without a tail.
.msg.sent.last
A right-aligned blue bubble with a tail.
.msg.received
A left-aligned gray bubble without a tail.
.msg.received.last
A left-aligned gray bubble with a tail.
.msg.pic.sent
A right-aligned image bubble without a tail.
.msg.pic.sent.last
A right-aligned photo bubble with its image extending into the tail.
.msg.pic.sent.info
A right-aligned image-and-text bubble without a tail.
.msg.pic.sent.info.last
A right-aligned image-and-text bubble with a tail.
.msg.pic.received
A left-aligned image bubble without a tail.
.msg.pic.received.last
A left-aligned photo bubble with its image extending into the tail.
.msg.pic.received.info
A left-aligned image-and-text bubble without a tail.
.msg.pic.received.info.last
A left-aligned image-and-text bubble with a tail.
.emoji.sent
Right-aligned emoji.
.emoji.received
Left-aligned emoji.
.sparetime
Adds spacing.
.timestamp
A centered timestamp.
1. Place the conversation inside a
.chat container.2. Put an
<img> inside a picture bubble. For a caption, add info and a <p> after the image.3. Add
last to the final message in a group to show its tail and spacing.4. Use
.timestamp for a centered time or status, and .sparetime for extra space.Example Code
A complete conversation showing how the message classes work together.

