Skip to content
Tutorials Center
My learning

Topics

Lesson 53 of 122 ยท The Head, Metadata and SEO

Social Sharing Previews

Control how your pages look when shared on social networks and chat apps with Open Graph and X card tags. Learn image sizes, fallbacks and how to test.

Paste a link into a chat app or a social network and, a moment later, it turns into a little card: a picture, a headline, a sentence of description and the site's name. That card is often the only part of your page people ever see, and it decides whether they click.

The card is built from tags in your page's head. Without them, each platform guesses, usually by grabbing the <title> and whatever image it finds first, which might be your logo, a tracking pixel or nothing at all. In this lesson you will write those tags yourself using the Open Graph protocol and X (Twitter) cards, choose images that crop well, and test the result.

When someone shares a URL, the platform's server (not the person's browser) fetches the page and reads its head. Two consequences follow:

  • The tags must be in the HTML the server sends. Link preview crawlers generally do not run JavaScript, so tags added by a script after the page loads are usually invisible to them.
  • Previews are cached. Platforms store the card for a while. Fix a typo in your tags and the old version may keep appearing until the cache is refreshed.

Open Graph: the common language

Open Graph was created by Facebook and is now read by almost every platform that shows link previews: social networks, chat and messaging apps, team tools and more. Each tag is a <meta> element with a property attribute (not name) and a content attribute:

HTML
<meta property="og:title" content="The Night Sky in October">
<meta property="og:description" content="Two meteor showers, a bright Saturn and the best nights for stargazing this month.">
<meta property="og:image" content="https://skywatch.example/images/october-card.jpg">
<meta property="og:url" content="https://skywatch.example/guides/october">
<meta property="og:type" content="article">

These five are the core set:

Tag Purpose
og:title The headline of the card. It can be shorter and punchier than your <title> and usually leaves out the site name.
og:description One or two sentences under the headline.
og:image The picture. Must be an absolute URL, ideally HTTPS.
og:url The canonical address of the page. Shares of ?utm_source=โ€ฆ variants are then grouped under one URL.
og:type What kind of thing this is: usually website for home and general pages, article for posts and news.

A few optional tags round out the card:

HTML
<meta property="og:site_name" content="Skywatch">
<meta property="og:locale" content="en_US">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta property="og:image:alt" content="A dark sky over a pine forest with meteor trails.">

og:image:width and og:image:height let platforms lay out the card before downloading the image. og:image:alt is the image's text alternative, used by platforms that support it; write it the way you would write an alt attribute (see Images).

For og:type article, you may add details such as the publication time:

HTML
<meta property="article:published_time" content="2026-10-01T08:00:00Z">
<meta property="article:section" content="Astronomy">

Let's turn a set of tags into a visible card. The script below reads the page's own Open Graph tags and draws a mock preview.

Preview card from Open Graph tags

The picture is a placeholder: the demo shows the image URL instead of fetching it. Now delete the og:title line and run the example again. The card falls back to the <title>, site name and all, which is what many platforms do. Remove og:image too and see how much less inviting the card becomes.

X (Twitter) cards

X reads its own twitter: tags first and falls back to Open Graph for anything missing. In practice you only need one extra tag to choose the card layout:

HTML
<meta name="twitter:card" content="summary_large_image">

Note that X tags use name, while Open Graph tags use property. The main card types are:

  • summary: a small square thumbnail beside the text.
  • summary_large_image: a large, wide image above the text. This is the usual choice for articles.

Optional extras include twitter:site (the site's account, such as @skywatch) and twitter:creator (the author's account). You can also override the title, description or image just for X with twitter:title, twitter:description, twitter:image and twitter:image:alt, but there is rarely a reason to: duplicating every Open Graph tag only adds weight.

Choosing the image

The image does most of the work, so it deserves some care:

  • Size and shape. An image of 1200 ร— 630 pixels (a ratio of about 1.91:1) is the most widely recommended size for large cards. It looks sharp on high-density screens without being huge.
  • Keep the important part central. Some apps crop previews to a square or a narrower rectangle. Put text and faces in the middle, with breathing room around the edges.
  • Use JPEG or PNG. They are understood everywhere. Support for WebP varies, and SVG is generally not accepted for previews.
  • Keep the file small. Well under a megabyte is a good target; very large images may be skipped or slow to appear.
  • Use absolute HTTPS URLs, and make sure the image is publicly reachable. An image behind a login or blocked to crawlers will not show.
  • Make text legible at small sizes. Cards are often displayed at a few hundred pixels wide. A large, short headline works; a paragraph does not.

One template, many cards. On a blog or shop, generate a card image per page (the article title on a branded background, or the product photo) rather than using one site-wide logo. Distinct images make shared links stand out in a busy feed.

A complete set

Here is a compact, complete head section for an article. It combines the tags from this lesson with the description from Page Titles and Descriptions:

HTML
<title>October Night Sky Guide โ€“ Skywatch</title>
<meta name="description" content="What to look for in the night sky this month: meteor showers, planets and moon phases.">
<link rel="canonical" href="https://skywatch.example/guides/october">

<meta property="og:type" content="article">
<meta property="og:site_name" content="Skywatch">
<meta property="og:title" content="The Night Sky in October">
<meta property="og:description" content="Two meteor showers, a bright Saturn and the best nights for stargazing this month.">
<meta property="og:url" content="https://skywatch.example/guides/october">
<meta property="og:image" content="https://skywatch.example/images/october-card.jpg">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta property="og:image:alt" content="A dark sky over a pine forest with meteor trails.">
<meta name="twitter:card" content="summary_large_image">

The example below checks a page for the tags it should have and reports what is missing, a small version of what dedicated preview tools do.

Social tag checker

Fix the problems one by one until every line turns green. Notice that the relative image path /images/mugs.jpg fails: a crawler on another server cannot know which site it belongs to.

Testing your previews

Because previews are built on someone else's server, you cannot see them by opening your page locally. A few ways to test:

  • Platform debugging tools. Some platforms offer an official inspector, such as Facebook's Sharing Debugger and LinkedIn's Post Inspector. They show which tags were found, warn about problems, and can refresh the cached preview after you change your tags.
  • Private test messages. Paste the link into a chat with yourself, or into a draft post, to see the real card. This is the most reliable check for apps without a debugger.
  • Preview tools. Browser extensions and online preview sites render cards for several platforms at once from your tags.

Remember that the page must be publicly reachable for any of these to work; a page on localhost or behind a login cannot be fetched.

Previews are not search results. Open Graph tags shape link cards, not search rankings. Search engines read your <title>, description and structured data instead.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which attribute do Open Graph tags use for their name?

    Open Graph tags are written as <meta property="og:title" content="โ€ฆ">. X card tags, by contrast, use name.
  2. 2. You add your Open Graph tags with JavaScript after the page loads. What is likely to happen?

    Link preview crawlers generally read the HTML the server sends. Put the tags in the server-rendered head.
  3. 3. Which image best suits a large link preview card?

    About 1200 ร— 630 (1.91:1) is the widely recommended size. Keeping key content central survives cropping, and JPEG or PNG works everywhere.
  4. 4. You fixed a typo in og:title, but the old title still appears when you share the link. Why?

    Platforms cache previews. Official debugging tools can usually fetch the page again and update the card.

Summary

  • Link previews are built by the platform's server from tags in your HTML head, and they are cached.
  • Open Graph (og:title, og:description, og:image, og:url, og:type) uses <meta property> and is read by nearly every platform.
  • X reads twitter: tags and falls back to Open Graph; twitter:card with summary_large_image is usually the only extra you need.
  • Use an absolute HTTPS image URL, about 1200 ร— 630, in JPEG or PNG, with important content centered and an og:image:alt.
  • Put the tags in the server-rendered HTML and test with platform debuggers or private test messages.

Next lesson: Structured Data.