Building a video card in pure CSS
Use aspect-ratio for the thumb, then layer a play button with grid.
7:42
2.1k views
Updated 2d ago
Home / Snippets / UI Components /
A clean preview card: 16:9 thumbnail, play overlay, title/description, and a compact metadata row you can drop into feeds and playlists.
.video-card {
border: 1px solid var(--card-border);
border-radius: var(--radius-lg);
background: var(--card);
overflow: clip;
}
.video-thumb {
aspect-ratio: 16 / 9;
position: relative;
}
.video-thumb .play {
position: absolute;
inset: 0;
display: grid;
place-items: center;
}
Includes role, constraints, two framework variants, and edge cases to handle.
You are a senior frontend engineer implementing a video preview card.
Goal: A responsive card with a 16:9 thumbnail, a centered play overlay, and a metadata section (title, description, chips).
Technical constraints:
- Use aspect-ratio: 16 / 9 for the thumbnail container.
- Use CSS grid (place-items: center) to center the play overlay.
- Use border-radius + overflow: clip on the card to clip the thumbnail edges.
- Ensure the play overlay is purely decorative (aria-hidden) unless it is a real button.
- Use oklch() for any explicit colors and var(--*) tokens for surfaces/borders where possible.
Framework variant (pick one):
A) Vanilla HTML/CSS card component.
B) React component <VideoCard /> with props: title, description, duration, views.
Edge cases to handle:
- Long titles: clamp lines with line-clamp or max-height and overflow.
- Small widths: stack metadata neatly and keep chips wrapping.
- Reduced motion: avoid hover-only affordances; keep it readable without animations.
Return HTML + CSS.
Video-style cards show up everywhere: course dashboards, changelogs, knowledge bases, and product onboarding. A predictable structure (thumb → overlay → metadata) helps users scan quickly, and the implementation is now simpler than ever thanks to aspect-ratio.
aspect-ratio gives you a stable thumbnail box before images load, reducing layout shift. The overlay uses an absolute-positioned layer with display: grid and place-items: center, which is the shortest way to center a play affordance without extra wrappers.
If the card is clickable, use a real link/button for the interactive target and keep decorative overlay elements aria-hidden. For performance, the whole pattern is static layout: no scripts required, and aspect-ratio helps prevent CLS.