Peekly

Open Graph tags in Next.js

The App Router writes the meta tags for you. Export a metadata object from a Server Component, and add an opengraph-image file when you want the image generated. Deploy it, then paste that public URL into the checker above.

Free. No signup. Public pages only.

Add the tags

  • The metadata object. Only a Server Component can export metadata. A file marked "use client" cannot. Set metadataBase once, in the root layout, to your absolute origin. Relative image and canonical paths are joined to it, and a relative path without metadataBase fails the build. An absolute URL in a field ignores metadataBase. title and description are the document title and the meta description. Repeat them on openGraph so the share card has its own title and description. Set twitter.card to summary_large_image, or X shows a small thumbnail. X will fall back to og:image, but the card type is what selects the large layout. When the title depends on the route, export generateMetadata instead of a static object. In Next.js 15, params on that function is a Promise, so await it before you read the slug.
    import type { Metadata } from "next";
    
    export const metadata: Metadata = {
      title: "Post title",
      description: "One or two sentences.",
      openGraph: {
        title: "Post title",
        description: "One or two sentences.",
        url: "/post",
        images: [
          {
            url: "/og.png",
            width: 1200,
            height: 630,
          },
        ],
      },
      twitter: {
        card: "summary_large_image",
        title: "Post title",
        description: "One or two sentences.",
        images: ["/og.png"],
      },
    };
  • opengraph-image. Put opengraph-image.tsx, or a png, jpg, or gif of that name, in the route segment. Next.js serves the file and adds og:image, og:image:type, og:image:width, and og:image:height. Export alt and it adds og:image:alt. A file deeper in the tree replaces one above it. When twitter.images is unset, Next.js copies the Open Graph images onto the Twitter card, and if a Twitter image is present while twitter.card is unset it emits summary_large_image. Set the card in metadata anyway, so the choice sits in the file you maintain. Add a twitter-image file only when that image should differ. A static opengraph-image over 8 MB, or a twitter-image over 5 MB, fails the build. The code version uses ImageResponse from next/og. The JSX it accepts is flexbox; display:grid will not work. On a dynamic route the image function can read params. Next.js 15.5 passes that value as a plain object. Newer App Router docs type it as a Promise. Follow the types in the version you have installed.
    import { ImageResponse } from "next/og";
    
    export const alt = "Post title";
    export const size = { width: 1200, height: 630 };
    export const contentType = "image/png";
    
    export default function Image() {
      return new ImageResponse(
        (
          <div
            style={{
              fontSize: 64,
              background: "white",
              width: "100%",
              height: "100%",
              display: "flex",
            }}
          >
            Post title
          </div>
        ),
        { ...size },
      );
    }
  • What a crawler receives. On a static page the tags are in the first HTML response. On a dynamic page Next.js can stream metadata after the UI, except for crawlers on its htmlLimitedBots list, which includes Twitterbot and Slackbot. Those still get the tags in the initial HTML. The checker above sends a user agent that includes Twitterbot, so a Next.js page returns the tags in that first response. A WordPress theme and a Shopify theme have the same requirement: the tags have to be in the HTML the server sends. Those steps are the WordPress Open Graph and Shopify Open Graph pages. Astro, Nuxt, Remix, and SvelteKit have that same requirement. Those steps are the Astro Open Graph, Nuxt Open Graph, Remix Open Graph, and SvelteKit Open Graph pages. Paste the public URL, not a localhost address. The checker only fetches public pages, and it grades og:title, og:description, og:image, and the Twitter card from the HTML your server sends.

Tags covered: og:title · og:description · og:image · og:url · twitter:card · twitter:image

More checkers

Twitter Card ValidatorOpen Graph CheckerLinkedIn Link Preview CheckerDiscord Embed PreviewWhatsApp Link Preview CheckerSlack Link Preview CheckeriMessage Link Preview CheckerFacebook Link Preview CheckerOpen Graph Image SizeTelegram Link Preview CheckerReddit Link Preview CheckerRefresh a Link Preview CacheBluesky Link Preview CheckerMastodon Link Preview CheckerMicrosoft Teams Link Preview CheckerFix a Broken Open Graph PreviewInstagram Link Preview CheckerPinterest Link Preview CheckerTikTok Link Preview CheckerYouTube Link Preview CheckerThreads Link Preview CheckerSnapchat Link Preview CheckerHow to Add Open Graph TagsOpen Graph Image Not UpdatingDiscord Link PreviewX (Twitter) Link PreviewWordPress Open GraphShopify Open GraphAstro Open GraphNuxt Open GraphRemix Open GraphSvelteKit Open GraphAll platforms

What each platform reads

  • X / Twittertwitter:card, twitter:* → og:* fallback1200×630 (min 300×157), < 5 MB
  • Facebookog:title, og:description, og:image1200×630, 1.91:1
  • LinkedInog:title, og:image (og: only)1200×627, 1.91:1
  • Discordog:site_name, og:*, theme-color, twitter:cardLarge image needs summary_large_image
  • Slackog:site_name, og:title, og:description, og:image1200×630
  • WhatsAppog:title, og:description, og:imageKeep < 300 KB

Guidance based on each platform's public documentation and observed behavior. Platforms change their rules without notice.

FAQ

+What is the Next.js Open Graph page for?

Add Open Graph and Twitter card tags in the Next.js App Router with the metadata API and an opengraph-image file, then test the HTML the server sends.

+Which tags does the Next.js Open Graph page cover?

Next.js Open Graph covers og:title, og:description, og:image, og:url, twitter:card, twitter:image.

+What does Next.js Open Graph say about "The metadata object"?

Only a Server Component can export metadata. A file marked "use client" cannot. Set metadataBase once, in the root layout, to your absolute origin. Relative image and canonical paths are joined to it, and a relative path without metadataBase fails the build. An absolute URL in a field ignores metadataBase. title and description are the document title and the meta description.

$9

One time

A written fix for the batch.

Up to 25 URLs. We check og:image, Twitter cards, size, redirects, and cache, then send copy-paste meta tags within 48 hours. The free single-URL check stays free.

Get the fix report — $9 (opens in a new tab)