SEO & Metadata
Next.js includes a Metadata API that allows you to define metadata to improve your application's SEO. This guide includes ready-to-copy examples for your Next.js project.
Below is a complete example of the metadata setup, so you can easily copy it into your app/layout.jsx
For pages with dynamic content (blogs, products, etc.), use generateMetadata()
Automatically generate Open Graph images using Next.js. Create app/opengraph-image.tsx or app/[route]/opengraph-image.tsx for dynamic routes. Next.js will automatically generate the image and add the correct meta tags.
Next.js automatically generates sitemap.xml and robots.txt files. Create app/sitemap.js and app/robots.js in your app directory. These files will be automatically served at /sitemap.xml and /robots.txt.
Additional SEO Tips
- OG Images: Use 1200x630px for Open Graph (Facebook, LinkedIn)
- Twitter Images: 1200x600px works best for Twitter Cards
- Description: Between 150-160 characters is ideal for Google
- Title: Maximum 60 characters to avoid truncation in results
- Keywords: 5-10 relevant keywords is sufficient