---
description: Link previews / share cards: Open Graph and X card meta tags (required tags, absolute image URLs, image size rules, Next.js metadata pitfalls, testing with curl)
globs: **/layout.tsx, **/layout.jsx, **/page.tsx, **/page.jsx, **/opengraph-image.*, **/twitter-image.*, index.html, **/index.html, **/_document.tsx, **/head.tsx
alwaysApply: false
---
# Open Graph and X card rules (link previews)

When you add or change page metadata, share images or <head> tags, follow these rules so links show a real preview card on X, Slack and other apps.
Checked on 2026-11-23 against the Open Graph protocol (https://ogp.me/), X's Summary Card with Large Image docs (archived copy, Feb 2026) and the Next.js metadata docs. If unsure whether a rule still holds, read those pages instead of guessing.

## Required tags on every shareable page
- Always set og:title, og:type, og:url and og:image. ogp.me calls these the four required properties for every page.
- If you set og:image, also set og:image:alt (what the image shows, not a caption).
- Add og:description (one or two sentences about THIS page).
- For a big image card on X, set twitter:card to summary_large_image and set twitter:title. X's docs mark both as required for that card. twitter:description, twitter:image and twitter:image:alt are optional but worth setting.
- Each page gets its own title, description and og:url. Do not copy the homepage values onto every page.

## URLs
- og:image, og:url and twitter:image must be full absolute URLs starting with https:// (ogp.me defines URL values as http:// or https:// URLs). Never write a relative path like /og.png in raw HTML.
- og:url is the canonical URL of the page, not a preview or staging URL.
- The image must load for a logged-out visitor: not behind a login, a preview-only deployment, or deployment protection.

## The image
- For summary_large_image, X's docs say: 2:1 aspect ratio, at least 300x157, at most 4096x4096 pixels, under 5MB, JPG, PNG, WEBP or GIF (first frame only), SVG not supported. 1200x600 PNG or JPG fits.
- X's docs say not to use a generic image such as the site logo. Make an image that says what the page is.
- If you write og:image:width and og:image:height, they must match the real file. Never invent dimensions; check the file or leave them out.
- Do not claim a size or format rule for a platform unless its docs state it. Say "their docs don't say" instead of guessing.

## Tags must be in the HTML the server sends
- Preview crawlers read the HTML response. Tags added by client-side JavaScript after load (for example React code that sets document.title or injects meta tags in a Vite, Lovable or Bolt app) may not be seen. Put the tags in index.html or use the framework's server-side metadata.

## Next.js App Router
- Set metadataBase once in the root layout (for example metadataBase: new URL('https://example.com')). The docs say a relative path in a URL-based metadata field without metadataBase causes a build error; an absolute URL in a field ignores metadataBase.
- Metadata from layouts and pages is merged shallowly. If a page sets openGraph: { title }, the layout's openGraph images are gone for that page. Repeat images in the page's openGraph (or read them from parent in generateMetadata). Same for twitter.
- Easiest image: an opengraph-image.(png|jpg) file in the route folder, plus opengraph-image.alt.txt for the alt text. Next.js writes the og:image, type, width and height tags. Same for twitter-image. Build fails if twitter-image is over 5MB or opengraph-image is over 8MB.
- In Next.js 16, params in generateMetadata and in opengraph-image code is a Promise: const { slug } = await params.

## Before saying it's done
1. curl -sL https://YOUR-URL | grep -iE 'og:|twitter:' and confirm every tag above is present with absolute URLs.
2. curl -sIL https://YOUR-IMAGE-URL and confirm HTTP 200, an image/ content type, and a size under 5MB.
3. Tell the user that platforms cache previews: test with a fresh post or a new URL, not one already shared.
4. List any tag you could not verify instead of claiming it works.
