This post will help you if you want to get the preview image for a YouTube video. You may want to you this if you want to trigger the video to launch in a pop up window, or you want to link to the video.

I'm not sure how far back it goes, but it works for PSY's Gangnam Style which is from July 2012 and Justin Beiber's Baby which is from February 2010.

You need the id of the video which is in the url after v=
https://www.youtube.com/watch?v=cIboJm2WzKY

When you have the video id, you can use it in this url to get the image.
URL

https://i.ytimg.com/vi/{0}/maxresdefault.jpg
@{
string youTubeId = "cIboJm2WzKY";
const string YOUTUBE_PREVIEW_IMAGE_URL = "https://i.ytimg.com/vi/{0}/maxresdefault.jpg";
}

<img src="@String.Format(YOUTUBE_PREVIEW_IMAGE_URL, youTubeId)" />

//The output will be

<img src="https://i.ytimg.com/vi/cIboJm2WzKY/maxresdefault.jpg">

I trust this has been pretty straight forward for you to follow. If you have any questions, feel free to write them in the comments. Don't forget to share this post with your friends and colleagues.

Want to thank me?

If I've helped you out and you want to thank me, why not buy me a coffee?

About the author

Paul Seal

Umbraco MVP and .NET Web Developer from Derby (UK) who specialises in building Content Management System (CMS) websites using MVC with Umbraco as a framework. Paul is passionate about web development and programming as a whole. Apart from when he's with his wife and son, if he's not writing code, he's thinking about it or listening to a podcast about it.

Related Posts

How to flip an image using CSS

In this post, Mike Masey shows you how you can flip an image using CSS.

Read Post

How to create a Carousel in Umbraco using Nested Content and Bootstrap

This post will show you how to build a carousel in umbraco using Nested Content and Bootstrap

Read Post

HTML Extension method for returning formatted HTML from a string in C#

This post shows you how to create an extension method for returning formatted HTML from a string inp…

Read Post

The day I hacked Troy Hunt's website to delete my data

I needed to remove my personal details from Troy Hunt's website. This post shows you why and how I d…

Read Post