Open Graph Tags in Next.js
Create Open Graph metadata, Twitter cards, canonical URLs, and social preview images for Next.js App Router pages.
Quick answer: which Open Graph tags matter in Next.js?
For most App Router pages, review `openGraph.title`, `openGraph.description`, `openGraph.url`, `openGraph.images`, `openGraph.type`, and matching Twitter card fields. The Next.js Metadata API renders those fields into the final document head.
Open Graph metadata example
Use Open Graph metadata when links need a useful preview in Slack, LinkedIn, Discord, X, and other sharing surfaces.
import type { Metadata } from "next";
export const metadata: Metadata = {
title: "Pricing",
description: "Compare plans for a developer tool workspace.",
openGraph: {
title: "Pricing",
description: "Compare plans for a developer tool workspace.",
url: "/pricing",
siteName: "Example",
images: [
{
url: "/og/pricing.png",
width: 1200,
height: 630,
alt: "Pricing page preview",
},
],
type: "website",
},
};Twitter card example
Twitter card fields should usually mirror the Open Graph title, description, and image so previews stay consistent across networks.
export const metadata = {
twitter: {
card: "summary_large_image",
title: "Pricing",
description: "Compare plans for a developer tool workspace.",
images: ["/og/pricing.png"],
},
};Canonical and Open Graph URL alignment
Open Graph URL and canonical URL should usually point to the same public page. If they drift accidentally, crawlers and social platforms can show inconsistent page identity.
- Set `alternates.canonical` for the canonical URL.
- Set `openGraph.url` to the same public page for normal content pages.
- Use campaign URLs only when the preview should intentionally represent a campaign page.
Image checklist
Social preview images should be inspectable, page-specific when useful, and large enough for preview surfaces. Avoid generic images when the page topic is specific.
- Use 1200 by 630 as a reliable default image size.
- Add useful alt text for preview images.
- Use `metadataBase` or absolute URLs so image paths resolve correctly.
- Verify the image is not blocked by robots, auth, or missing deployment assets.
Common mistakes
Most Open Graph issues come from missing absolute image URLs, duplicated titles, stale images, or dynamic pages that generate the same preview for every route.
- Do not reuse a homepage title on every dynamic route.
- Do not let canonical and Open Graph URLs point at different canonical pages by accident.
- Do not ship placeholder social images on product, guide, or comparison pages.
Generator workflow
Use the Next Metadata generator to create a consistent starter, paste it into the App Router route, then hand-edit the copy and image fields for the page's actual search and social intent.
Use FrameworkKit to generate the starter code, then review the output before shipping it in production.
Generate with Next Metadata GeneratorNext Metadata resources
Next Metadata generator
Generate typed App Router metadata, canonical URLs, Open Graph fields, and Twitter cards.
Next Metadata examples
Start from static page, dynamic route, and social preview examples before adapting the output.
Next.js Metadata API examples
Compare static metadata, generateMetadata, metadataBase, canonical URLs, and Open Graph fields.
Next Metadata generator vs manual SEO
Choose when a generated starter is enough and when dynamic pages need hand-written metadata.
FAQ
Does Next.js support Open Graph tags through metadata?
Yes. The App Router Metadata API supports Open Graph fields through the `openGraph` object and renders the corresponding meta tags.
Should Open Graph URL match the canonical URL?
Usually yes. For normal pages, canonical URL and Open Graph URL should identify the same public page so crawlers and social previews stay aligned.
What Twitter card should I use for most pages?
Use `summary_large_image` when the page has a useful preview image. Use a smaller summary card only when imagery is not important.
Why is my Open Graph image missing?
Common causes include a missing `metadataBase`, a relative URL that does not resolve, a blocked image asset, or an image path that was not deployed.
Related comparisons
Related tools
Zod to JSON Schema Converter
Use a free browser-only online converter to turn Zod 4 schemas into JSON Schema for Draft 2020-12, Draft 7, AJV, or OpenAPI-compatible output.
JSON to Zod Converter
Convert JSON to Zod schemas with strict objects, optional field inference, and inferred TypeScript types.
tsconfig Builder
Build sane TypeScript compiler presets for Next.js, Vite, libraries, Node, and monorepos.