Back to results for “Media”
Next.js › Metadata API & SEO Optimization

How do you add Open Graph and Twitter card metadata so your pages look good when shared on social media?

Intermediate

Answer

You include openGraph and twitter fields inside your metadata object, specifying an image, title, and description that social media platforms use to build an attractive preview card whenever someone shares a link to your page, rather than showing a plain, unstyled link.
export const metadata = {
  openGraph: {
    title: 'My Article',
    description: 'An interesting read about web development.',
    images: ['/og-image.jpg']
  },
  twitter: {
    card: 'summary_large_image'
  }
};
Real-world example A blog adds an eye catching preview image and description to its articles, so when readers share links on social media, a rich visual card appears instead of a plain, boring text link.

Common follow-ups: What image dimensions work best for Open Graph preview images?;How do you test how a page's social media preview will actually look?