How can I add a thumbnail to my website so that when someone shares a link on Twitter or Facebook, he shows the image and the link?


How do I add a thumbnail to my website so when a user shares the link to Twitter or Facebook it shows the link with the image in HTML and Javascript? So what I exactly want is that when the user shares the link of my website on any social media a thumbnail image comes beside it.

I've put a link of what I want below.

Those are called twitter cards and basically, you add <meta> tags to your page to tell Twitter what to show on them.

I think the type of card you are looking for is this one:

Here is a snippet with examples how it would work (taken from the docs):

<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@nytimes">
<meta name="twitter:creator" content="@SarahMaslinNir">
<meta name="twitter:title" content="Parade of Fans for Houston’s Funeral">
<meta name="twitter:description" content="NEWARK - The guest list and parade of limousines with celebrities emerging from them seemed more suited to a red carpet event in Hollywood or New York than than a gritty stretch of Sussex Avenue near the former site of the James M. Baxter Terrace public housing project here.">
<meta name="twitter:image" content="">

They even provide you with a service to validate and preview the cards:

For Facebook, the <meta> tags are different and are also well documented here:

As with Twitter, they also provide a page where you can validate and preview:

Hope that helps!