Menu

Preview a YouTube thumbnail at feed size with CSS
📰

Preview a YouTube thumbnail at feed size with CSS

DEV Community: css·hubvanta·about 6 hours ago
#48W03CB3
#devtocss#devto#dev#preview#thumbnail
Reading 0:00
15s threshold

When a creator tool displays a thumbnail in a card, the exported 16:9 image is usually much larger than the preview. Text that looks fine in the editor can disappear at a card width of 160 or 320 pixels. I use two preview sizes and a consistent crop before choosing a layout.

<div class = "thumbnail" ><img src = "thumbnail.jpg" alt = "Preview of the thumbnail" ></div>

Enter fullscreen mode

Exit fullscreen mode

.thumbnail { width : min ( 100 % , 320px ) ; aspect-ratio : 16 / 9 ; }

.thumbnail img { width : 100 % ; height : 100 % ; object-fit : cover ; object-position : center ; display : block ; }

Enter fullscreen mode

Exit fullscreen mode

Change the width to 160px for the second view. If the preview cuts off a face or heading, compare object-position: 35% center with the centred version. A CSS crop only affects the preview.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.