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.pngaren't resolved by many crawlers.og:url: the canonical URL; share counts and caches are grouped by it.og:type:websitefor most pages,articlefor posts.- Open Graph uses the
propertyattribute; Twitter cards usename. 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
- Tags rendered by JavaScript. Most preview crawlers don't execute scripts. Check with
curl -s URL | grep og:. - Relative image URL or an image behind authentication.
- Blocked crawlers. A firewall, bot protection or
robots.txtrule can blockfacebookexternalhit,LinkedInBot,Twitterbot,SlackbotorDiscordbot. - Redirects or errors. The crawler must get a
200response. Long redirect chains can fail; see HTTP redirects. - Unescaped quotes in content, which break the attribute. Escape
"as", as covered in escaping HTML. - 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
og:title,og:description,og:image(absolute, 1200 × 630),og:url,og:type.twitter:cardset tosummary_large_imagefor a large preview.- Tags in server-rendered HTML, using
propertyforog:andnamefortwitter:. - Image publicly reachable over HTTPS and not blocked for crawlers.
- Preview checked before sharing, and caches refreshed after changes.