Developer Tools

Open Graph Tags Explained: How Link Previews Actually Work

What each og: tag does, the image sizes Facebook and LinkedIn require, how Slack and others cache previews, a Next.js setup, and a live audit of our pages.

TechLogHub Editorial
December 3, 2026
14 min read
0 views

Share Article

TechLogHub cover: an HTML head with og:title, og:image and twitter:card tags becoming a 1200x630 link preview

Open Graph Tags Explained: How Link Previews Actually Work

Quick answer: Open Graph tags are <meta property="og:…"> tags in your page's <head> that tell Facebook, LinkedIn, Slack and most chat apps what title, description and image to show when someone shares your link. The spec requires four: og:title, og:type, og:image and og:url. In practice you also want og:description, og:image:alt, og:image:width and og:image:height, plus twitter:card. Use a 1200×630 image under 5 MB, keep the tags near the top of the <head>, and change the image URL whenever you change the image, because platforms cache by URL.

A link preview is the first impression most people get of your page, and you do not control it unless you tell each platform what to show. Without Open Graph tags, Facebook's documentation says its crawler "uses internal heuristics to make a best guess" at the title, description and image. Heuristics are how you end up with your cookie banner as the preview image.

The tags themselves are simple. The parts that go wrong are the details each platform layers on top: image size rules, caches keyed on URLs, crawlers that read only the first part of your page, and preview images that fail without anyone noticing. This guide covers what the protocol requires, what Facebook, LinkedIn and Slack add, a working Next.js setup, and an audit of five techloghub.com pages we ran on 3 December 2026, which found a broken preview image on four of them.

What Open Graph is and the four required tags

The Open Graph protocol started at Facebook as a way to turn any web page into "a rich object in a social graph." It is built on RDFa, which is why the tags use property= instead of the name= attribute that ordinary meta tags use. Every other major platform adopted it because it was already on millions of pages.

The spec lists four properties that every page needs:

  • og:title: the title as it should appear in the preview.
  • og:type: what kind of object the page is, such as website or article. Some types require extra properties.
  • og:image: an image URL that represents the page.
  • og:url: the canonical URL, which the spec calls the object's "permanent ID in the graph".

A minimal, correct block for a blog post:

<meta property="og:title" content="Open Graph Tags Explained" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://example.com/blog/open-graph-tags" />
<meta property="og:image" content="https://cdn.example.com/og/open-graph-tags-v1.png" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<meta property="og:image:alt" content="Diagram of a link preview built from og:title, og:description and og:image" />
<meta property="og:description" content="What each og: tag does, the image sizes platforms use, and how to debug a broken preview." />
<meta property="og:site_name" content="Example" />
<meta name="twitter:card" content="summary_large_image" />

You can write this by hand, or generate it with our Open Graph tag generator, which outputs the tags and a preview from a form.

Recommended optional tags

The protocol marks several more properties as optional but "generally recommended":

  • og:description: "a one to two sentence description". Facebook's guide says two to four sentences, so aim for one or two short ones that read well when truncated.
  • og:site_name: your site's name, shown separately from the page title. This is why Facebook asks for og:title "without any branding such as your site name". The brand goes here instead.
  • og:locale: the language and territory, in language_TERRITORY format. The default is en_US.
  • og:determiner: the word before the title in a sentence ("a", "an", "the"). Almost nobody needs it.

The image tags, and why width and height matter

og:image has structured properties that sit directly after it: og:image:url, og:image:secure_url, og:image:type, og:image:width, og:image:height and og:image:alt. The spec is firm on one of them: "If the page specifies an og:image it should specify og:image:alt." Alt text describes what is in the image for people using screen readers. It is not a caption.

Order matters. The protocol says structured properties attach to the most recent root tag, and a new og:image starts a new image. If you list several images, "the first tag (from top to bottom) is given preference during conflicts." Put the image you want first, with its width, height and alt directly under it.

Width and height look optional, but Facebook's image guide explains why they are not. The crawler "has to see an image at least once before it can be rendered", so "the first person who shares a piece of content won't see a rendered image." Facebook gives three ways around that. You can pre-scrape the URL in the Sharing Debugger, force a scrape through the Graph API, or declare og:image:width and og:image:height so the crawler "can render the image immediately without having to asynchronously download and process it." The third one costs two lines of HTML.

Image sizes by platform

Each platform publishes its own numbers. These are from their documentation, read on 3 December 2026:

PlatformMinimumRecommendedMax file sizeAspect ratioSource
Facebook200×200 (600×315 for the large layout)1200×630 or larger8 MBClose to 1.91:1Meta: Images in Link Shares
LinkedIn1200×6271200×6275 MB1.91:1LinkedIn Help
Next.js build checkn/a1200×630 in the docs example8 MB (opengraph-image), 5 MB (twitter-image)n/aNext.js docs

LinkedIn adds a detail worth knowing: images "less than 401 pixels wide display as a thumbnail image." Facebook says the same in softer terms: below 600×315 the image "will still display in the link page post, but the size will be much smaller."

The practical answer is one image at 1200×630, PNG or JPEG, under 5 MB. That meets Facebook's recommendation, sits within LinkedIn's limits (630 is above its 627 minimum and the ratio rounds to 1.91:1), and stays under the smallest file cap. Facebook lists og:image:type values as JPEG, GIF or PNG, so leave WebP and AVIF for your on-page images. If you need to convert, our image format converter runs in the browser.

Keep the important content away from the edges. Platforms crop slightly differently, and a centred headline survives all of them. Our OG image generator produces 1200×630 cards with safe margins built in.

How platforms fetch and cache your tags

The tags are only half the system. The other half is a crawler you do not control, fetching your page once and caching what it sees.

Facebook

Facebook's crawler identifies itself as facebookexternalhit/1.1. Its webmaster guide adds a requirement many servers miss: "your server must also use the gzip and deflate encodings." The image guide repeats it: the crawler "only accepts gzip and deflate encodings." If you serve only Brotli to everything, check what you send this user agent.

Facebook caches images by URL. The image guide says to "use a new URL for the new image or the image won't be updated", and not to delete old images because existing posts still reference them. Changing the file behind the same URL does nothing. Version the filename (cover-v2.png) or add a content hash.

The guide also says updating an image "will not automatically update the preview for old shares." You have to re-scrape the URL. The Sharing Debugger shows the tags Facebook sees, and it triggers a fresh scrape.

LinkedIn

LinkedIn's help page lists four og tags that "must exist": og:title, og:image, og:description and og:url. Note that og:description is required here even though the protocol marks it optional. LinkedIn also warns that if your image meets the requirements and still does not appear, "your website may be blocking us from pulling the image." Check your firewall and bot rules. That page says it was last updated three years ago, so test with LinkedIn's Post Inspector instead of trusting the numbers forever.

Slack

Slack's robots page has the most useful technical detail of any platform. Its link-expanding bot, Slackbot-LinkExpanding 1.0, "fetches as little of the page as it can (using HTTP Range headers) to extract meta tags." It looks for oEmbed, Twitter Card and Open Graph tags, fetches any referenced image to check it is valid, and caches responses globally "for around 30 minutes."

The Range detail has a direct consequence. If your <head> is bloated with inline CSS, large JSON-LD blocks or analytics scripts before the og tags, a client that reads only the first chunk of the page may never reach them. Put the og and twitter tags early in the <head>, before large inline payloads.

Slack also says it does not honour robots.txt for link expansion, because it acts "on behalf of a human" instead of crawling. A Disallow will not stop unfurls. If you need to block them, Slack asks you to contact it.

X (Twitter)

X reads its own twitter: tags, and twitter:card decides the layout. summary_large_image is the large image card most sites want. We tried to check X's current card documentation for this article. On 3 December 2026, the old developer.x.com card markup URLs redirected to the X API homepage, and we could not find the card spec on docs.x.com. So our advice is defensive: always set twitter:card, and also set twitter:title, twitter:description and twitter:image explicitly instead of relying on any fallback to og tags. Then post a test link and look.

Worked example: auditing five techloghub.com pages

We ran our own pages through the rules above. On 3 December 2026 we fetched five URLs from a browser tab on techloghub.com, parsed the HTML with DOMParser, and then requested each og:image URL. The script:

const pages = ['/', '/tools', '/compare', '/tools/og-tag-generator',
               '/blog/robots-txt-explained'];
for (const p of pages) {
  const html = await fetch(p).then(r => r.text());
  const doc = new DOMParser().parseFromString(html, 'text/html');
  const og = k => doc.querySelector(`meta[property="og:${k}"]`)?.content ?? null;
  const tw = k => doc.querySelector(`meta[name="twitter:${k}"]`)?.content ?? null;
  const img = await fetch(og('image')).then(r => r.status).catch(() => 'cors');
  console.log(p, {
    type: og('type'), site: og('site_name'), w: og('image:width'),
    alt: !!og('image:alt'), card: tw('card'),
    firstOgByte: html.indexOf('property="og:'), image: img,
  });
}

The results:

Pageog:typesite_namewidth/heightimage:alttwitter:cardFirst og tag at byteog:image response
/websiteyes1200×630yessummary_large_image2,667502 (/api/og)
/toolswebsiteyesmissingmissingsummary_large_image2,787502 (/api/og)
/comparewebsitemissingmissingyessummary_large_image2,833502 (/api/og)
/tools/og-tag-generatorwebsiteyes1200×630yessummary_large_image2,835502 (/api/og)
/blog/robots-txt-explainedarticleyesmissingyessummary_large_image3,075loads, 1200×630 (static file on our storage host)

What the audit says

Four of five preview images were failing. Every page that uses our dynamic /api/og image endpoint got an HTTP 502 when we requested the image, on two attempts several minutes apart. The tags were perfect and the preview would still be blank, because platforms validate the image itself. Slack's documentation says so explicitly: it fetches the referenced image "to check validity." This is the most common Open Graph failure, and it is invisible from the HTML. Validating tags is not enough. Request the image URL too.

The static blog cover worked. The blog post points at a pre-rendered PNG on a storage host, and it loaded at 1200×630. Static files have fewer moving parts than an image route that renders on request. If you use a dynamic generator, cache its output or pre-render at build time. Next.js does this by default: its docs say generated images "are statically optimized (generated at build time and cached) unless they use Request-time APIs or uncached data."

Width and height were missing on three pages. That includes the blog post. Per Facebook's image guide, without them the first person to share a post may get no image. It is a two-tag fix.

/tools had no og:image:alt, and /compare had no og:site_name. Neither breaks a preview. Both are cheap to add, and alt text is the one the spec says you should always pair with an image.

Tag placement was good. The first og tag sat within the first 3.1 KB of every page, and each <head> was 4–5 KB in total. Range-based fetchers like Slack's will find them.

The fix list for us is short: repair or cache /api/og, add width and height everywhere, add the missing alt and site name. We have flagged it internally.

Setting Open Graph tags in Next.js

The Next.js App Router gives you two ways to set these tags, and their precedence rules are worth knowing before you mix them.

File convention. Put opengraph-image.png (or .jpg, .gif) in a route folder and Next.js adds og:image, og:image:type, og:image:width and og:image:height for you. Add opengraph-image.alt.txt beside it for the alt text. The same pattern exists for twitter-image. The build fails if opengraph-image exceeds 8 MB or twitter-image exceeds 5 MB.

Generated images. Replace the image file with opengraph-image.tsx and return an ImageResponse from next/og:

// app/blog/[slug]/opengraph-image.tsx
import { ImageResponse } from 'next/og';

export const alt = 'Article cover';
export const size = { width: 1200, height: 630 };
export const contentType = 'image/png';

export default async function Image({ params }: { params: Promise<{ slug: string }> }) {
  const { slug } = await params;
  const post = await getPost(slug);
  return new ImageResponse(
    (
      <div style={{ width: '100%', height: '100%', display: 'flex',
                    alignItems: 'center', padding: 80, background: '#000',
                    color: '#fff', fontSize: 64, fontWeight: 800 }}>
        {post.title}
      </div>
    ),
    { ...size }
  );
}

Metadata object. The metadata export or generateMetadata sets every other tag:

export async function generateMetadata({ params }) {
  const post = await getPost((await params).slug);
  const url = `https://example.com/blog/${post.slug}`;
  return {
    alternates: { canonical: url },
    openGraph: {
      type: 'article', url, title: post.title, description: post.summary,
      siteName: 'Example', locale: 'en_US',
      images: [{ url: post.coverUrl, width: 1200, height: 630, alt: post.coverAlt }],
    },
    twitter: { card: 'summary_large_image', title: post.title,
               description: post.summary, images: [post.coverUrl] },
  };
}

The precedence rule from the docs: a page's explicit openGraph.images "overrides the corresponding opengraph-image" file, including files inherited from parent folders. So if a page sets openGraph.images, a colocated opengraph-image.png is ignored. Pick one approach per route.

Keep og:url identical to your canonical URL. Facebook says likes and shares "will aggregate at this URL", and it asks for "the undecorated URL, without session variables, user identifying parameters, or counters." If you are unsure how your canonical is set, our canonical tags guide and canonical tag generator cover it, and the meta tag generator handles the non-OG tags around them.

Debugging a broken preview

When a preview is wrong, work through this order. It moves from the cheapest check to the slowest.

  1. View the raw HTML. Use curl -s https://example.com/page | grep -i 'og:' or view-source. Client-side rendering is a common culprit: crawlers that do not run JavaScript never see tags injected after load.
  2. Request the image URL directly. Check for a 200, an image content type, and a size within the limits above. A 502, a redirect to a login page, or an HTML error page all produce a blank preview. That is what our audit caught.
  3. Fetch as the crawler. Facebook suggests switching your user agent to facebookexternalhit/1.1 and comparing the response with a normal browser. Bot protection rules often block these agents.
  4. Check encoding. Facebook requires gzip or deflate support.
  5. Clear the platform cache. Re-scrape in Facebook's Sharing Debugger and LinkedIn's Post Inspector. For Slack, wait out the roughly 30-minute cache.
  6. Version the image URL if you changed the image. Every platform here caches by URL.
SymptomLikely causeFix
No image on the first share onlyCrawler had not fetched the image yetAdd og:image:width and og:image:height, or pre-scrape
Old image keeps showingImage cached by URLNew filename or hash, then re-scrape
Small thumbnail instead of a large cardImage under 600×315 (Facebook) or under 401 px wide (LinkedIn)Use 1200×630
Wrong title or random imageTags missing or injected by client-side JavaScriptRender tags on the server
Blank preview, tags look rightImage URL errors, is blocked, or is too largeRequest it directly; check firewall and size
Works on Facebook, not on LinkedInog:description missingAdd it; LinkedIn lists it as required

If the problem is in your JSON-LD instead of your og tags, the JSON formatter makes a minified block readable enough to spot the error.

When Open Graph is not the problem

Open Graph controls how a link looks when shared. It has no documented effect on Google rankings, and it does not replace a <title> or meta description. Search engines generate their own snippets.

It also cannot fix a page that people do not want to share. A perfect card on a thin page is still a thin page. And some platforms prefer oEmbed for rich media: Slack checks for oEmbed alongside Open Graph. If you host video or interactive embeds, an oEmbed endpoint may give you a better result than an og:video tag.

Finally, generated preview images add a dependency. Each share triggers an image request, and if that route is slow or down, every preview fails at once. Our audit is the example. A static image per page, rendered once when the page is published, is the boring choice that keeps working.

FAQ

What are the required Open Graph tags?

The Open Graph protocol requires four: og:title, og:type, og:image and og:url. LinkedIn also lists og:description as required, and the spec says any page with og:image should include og:image:alt. Adding og:image:width and og:image:height helps Facebook render the image on the first share.

What size should an Open Graph image be?

Use 1200×630 pixels, PNG or JPEG, under 5 MB. Facebook recommends at least 1200×630 with a ratio close to 1.91:1 and allows up to 8 MB, while LinkedIn asks for at least 1200×627 and at most 5 MB, so 1200×630 under 5 MB works on both.

Why is my old preview image still showing?

Facebook caches images by their URL, so replacing the file behind the same URL does not update the preview. Upload the new image under a new URL, update og:image, then re-scrape the page in Facebook's Sharing Debugger or LinkedIn's Post Inspector.

Do I need Twitter card tags if I have Open Graph tags?

Set them anyway. X uses twitter:card to choose the card layout, and summary_large_image gives the large image card. We could not reach X's current card documentation on 3 December 2026, so we set twitter:title, twitter:description and twitter:image explicitly rather than relying on a fallback.

Does robots.txt stop Slack from unfurling my links?

No. Slack's robots page says its link-expanding bot does not honour robots.txt because it acts on behalf of a user rather than crawling. To block unfurls from your site, Slack asks you to contact it.

Do Open Graph tags help SEO?

Not directly. Open Graph controls how links look on social and chat platforms, and neither Google nor the protocol documents it as a ranking factor. A better preview can earn more clicks from shares, but the title tag and meta description still drive search snippets.


Platform limits and our audit results were checked on 3 December 2026. Social platforms change their crawlers and image rules without much notice, so test a real share after any change.

Stay Updated

Get the next deep dive in your inbox

Subscribe for product analysis, engineering explainers, and practical guides published on TechLogHub.

See what launched this week

One email a week: new and trending developer tools, fresh comparisons, and what shipped. Unsubscribe in one click.