Direct Message Preview Card
Build a clean and functional inbox interface with this direct message preview card.
This component is a vital part of any application with messaging features. It displays a list of conversations, showing the sender's avatar, their name, a snippet of the latest message, and a timestamp, with a clear visual indicator for unread items.

About this Component
This template is designed to be used as an item within a list. A simple modifier class, .is-unread
, is used to change the visual weight of unread messages, making them stand out. The layout uses Flexbox to ensure the avatar, text content, and metadata are all neatly aligned.
Features
- Unread State Indicator: The
.is-unread
class makes the sender's name and message bold and displays a colored dot to draw the user's attention. - Text Truncation: Long message previews are automatically truncated with an ellipsis (...) to prevent them from breaking the layout.
- Semantic Structure: The entire component is built inside a semantic unordered list, which is the correct structure for a list of items.
Code Breakdown
HTML Structure
The entire inbox is a ul
, with each message preview being a li
. To mark a message as unread, you add the .is-unread
class to its li
. The content of the list item is a single clickable a
tag that holds all the visual elements (an img
for the avatar, a content div
, and a metadata div
).
CSS Styling
The layout is achieved using Flexbox on the main anchor tag. The central content block (.dm-content
) is given flex-grow: 1
, which makes it take up all available horizontal space and pushes the metadata block to the far right. The message snippet truncation is done with a trio of properties on the .dm-message-preview
class: white-space: nowrap
, overflow: hidden
, and text-overflow: ellipsis
. The "unread" state is styled entirely by CSS rules that are scoped to the .is-unread
parent class.
Code
Here is the complete, self-contained code. To build an inbox, simply populate the ul
with a li
for each message, adding the .is-unread
class as needed.