This guide shows you the way.
Extract video ID from the embed code, then use img.youtube.com/vi/ID/hqdefault.jpg
(standard).
You can also use /maxresdefault.jpg
at the end of the URL to get the thumbnail in full size.
src
attribute within the iframe
tag. It contains the video URL.This 11-character string is the video ID.
https://img.youtube.com/vi/VIDEO_ID/hqdefault.jpg
https://img.youtube.com/vi/VIDEO_ID/maxresdefault.jpg
For dynamic extraction on a website:
function getYouTubeThumbnail(embedCode) {
const videoId = embedCode.match(/watch\?v=(.*?)(&|$)/)[1];
return `https://img.youtube.com/vi/${videoID}/hqdefault.jpg`;
}
const thumbnailUrl = getYouTubeThumbnail(embedCode);
// Use the thumbnailUrl as needed
If the embed code is unavailable, use the video URL directly to get the thumbnail.
Keep in mind that YouTube’s HTML structure can change,Β so these methods might not always forever. At one point, they might need adjustments.
Also, be sure to:
That’s right about it. All you need to know!
Thank you for reading this,
Thumbnail Test