All articles

Open Graph meta tags: a complete guide

· 3 min read

When someone shares your URL in a chat app, on LinkedIn or on X, the platform fetches the page and builds a preview card from its meta tags. Without them, it guesses, often picking a random image or none at all. The Open Graph protocol, created by Facebook, is what nearly every platform reads.

The essential tags

<head>
  <title>Release notes: Version 4.2</title>
  <meta name="description" content="Dark mode, faster search and a new export option.">

  <meta property="og:title" content="Release notes: Version 4.2">
  <meta property="og:description" content="Dark mode, faster search and a new export option.">
  <meta property="og:image" content="https://example.com/og/release-4-2.png">
  <meta property="og:image:width" content="1200">
  <meta property="og:image:height" content="630">
  <meta property="og:image:alt" content="Screenshot of the app in dark mode">
  <meta property="og:url" content="https://example.com/releases/4-2">
  <meta property="og:type" content="article">
  <meta property="og:site_name" content="Example">

  <meta name="twitter:card" content="summary_large_image">
</head>

Notes on each:

  • og:title: the headline on the card. It can differ from <title>, which often includes the site name.
  • og:description: one or two sentences. Platforms truncate long text, so put the important part first.
  • og:image: must be an absolute URL. Relative paths like /og.png aren't resolved by many crawlers.
  • og:url: the canonical URL; share counts and caches are grouped by it.
  • og:type: website for most pages, article for posts.
  • Open Graph uses the property attribute; Twitter cards use name. Mixing them up is a common reason tags are ignored.

Twitter (X) cards

X reads Open Graph tags as fallbacks, so you only need twitter:card in most cases:

Tag Purpose
twitter:card summary (small square image) or summary_large_image
twitter:title, twitter:description, twitter:image Only if they should differ from the og: values
twitter:site The site's @handle

Image requirements

  • Size: 1200 × 630 px (about 1.91:1) works well for large cards across platforms. Keep important content in the center, since some apps crop to a square.
  • Format: PNG or JPEG. WebP works on many platforms but not all; SVG generally doesn't.
  • File size: keep it well under 5 MB; smaller images are fetched more reliably.
  • Accessible: the URL must be public, served over HTTPS, without login, and not blocked by robots.txt.
  • Text: large and short. Previews are often shown at small sizes.

Framework examples

Next.js (App Router)

// app/releases/[slug]/page.tsx
export async function generateMetadata({ params }) {
  const { slug } = await params;
  const release = await getRelease(slug);
  return {
    title: release.title,
    description: release.summary,
    openGraph: {
      title: release.title,
      description: release.summary,
      url: `https://example.com/releases/${slug}`,
      type: "article",
      images: [{ url: `/og/${slug}.png`, width: 1200, height: 630, alt: release.imageAlt }],
    },
    twitter: { card: "summary_large_image" },
  };
}

Set metadataBase in the root layout so relative image paths become absolute. An opengraph-image.tsx file can generate the image from code at build or request time.

Static sites and other frameworks

Most frameworks have a head API: useHead in Nuxt, <svelte:head> in SvelteKit, front matter templates in Hugo and Astro. The key requirement is that tags are in the server-rendered HTML.

Why previews don't show up

  1. Tags rendered by JavaScript. Most preview crawlers don't execute scripts. Check with curl -s URL | grep og:.
  2. Relative image URL or an image behind authentication.
  3. Blocked crawlers. A firewall, bot protection or robots.txt rule can block facebookexternalhit, LinkedInBot, Twitterbot, Slackbot or Discordbot.
  4. Redirects or errors. The crawler must get a 200 response. Long redirect chains can fail; see HTTP redirects.
  5. Unescaped quotes in content, which break the attribute. Escape " as &quot;, as covered in escaping HTML.
  6. Caching. Platforms keep previews for days or longer.

Refreshing a cached preview

  • Facebook: the Sharing Debugger has a "Scrape Again" button.
  • LinkedIn: the Post Inspector fetches the latest version.
  • Slack, Discord, X: no public refresh tool; changing the URL (for example adding ?v=2) produces a fresh preview.

When the image changes, publish it under a new file name too; caches key on the image URL as well as the page.

Checklist

  1. og:title, og:description, og:image (absolute, 1200 × 630), og:url, og:type.
  2. twitter:card set to summary_large_image for a large preview.
  3. Tags in server-rendered HTML, using property for og: and name for twitter:.
  4. Image publicly reachable over HTTPS and not blocked for crawlers.
  5. Preview checked before sharing, and caches refreshed after changes.

Frequently asked questions

Do Open Graph tags help SEO?

Not directly as a ranking factor. They improve how links look when shared, which can increase clicks. The HTML title and meta description still matter for search results.

Why does my preview show an old image?

Platforms cache previews. Use the Facebook Sharing Debugger or LinkedIn Post Inspector to re-scrape, and change the image URL (for example with a version query) so caches fetch the new file.

Can the og:image be an SVG?

Most platforms don't render SVG previews. Use PNG or JPEG.

Do client-side rendered pages work?

Usually not. Most link preview crawlers don't run JavaScript, so tags must be in the HTML the server sends.

Further reading