OG Image Generation
Important
Stay updated on React2Shell

Open Graph (OG) Image Generation

Last updated November 19, 2025

To assist with generating dynamic Open Graph (OG) images, you can use the Vercel library to compute and generate social card images using Vercel Functions.

  • Performance: With a small amount of code needed to generate images, functions can be started almost instantly. This allows the image generation process to be fast and recognized by tools like the Open Graph Debugger
  • Ease of use: You can define your images using HTML and CSS and the library will dynamically generate images from the markup
  • Cost-effectiveness: automatically adds the correct headers to cache computed images at the edge, helping reduce cost and recomputation
  • Basic CSS layouts including flexbox and absolute positioning
  • Custom fonts, text wrapping, centering, and nested images
  • Ability to download the subset characters of the font from Google Fonts
  • Compatible with any framework and application deployed on Vercel
  • View your OG image and other metadata before your deployment goes to production through the Open Graph tab

Vercel OG image generation is supported on the Node.js runtime.

Local resources can be loaded directly using . Alternatively, can be used to load remote resources.

There are limitations when using with the Next.js Pages Router and the Node.js runtime. Specifically, this combination does not support the syntax. The table below provides a breakdown of the supported syntaxes for different configurations.

ConfigurationSupported SyntaxNotes
+ Edge runtimeFully supported.
+ Node.js runtimeFully supported.
+ Edge runtimeFully supported.
+ Node.js runtimeNot supportedDoes not support syntax with .
  • Install Node.js 22 or newer by visiting nodejs.org
  • Install by running the following command inside your project directory. This isn't required for Next.js App Router projects, as the package is already included:
  • For Next.js implementations, make sure you are using Next.js v12.2.3 or newer
  • Create API endpoints that you can call from your front-end to generate the images. Since the HTML code for generating the image is included as one of the parameters of the function, the use of or files is recommended as they are designed to handle this kind of syntax
  • To avoid the possibility of social media providers not being able to fetch your image, it is recommended to add your OG image API route(s) to inside your file. For example, if your OG image API route is , you can add the following line: If you are using Next.js, review robots.txt to learn how to add or generate a file.

Get started with an example that generates an image from static text using Next.js by setting up a new app with the following command:

Then paste the following code:

If you're not using a framework, you must either add "type": "module" to your package.json or change your JavaScript Functions' file extensions from .js to .mjs

Run the following command:

Then, browse to . You will see the following image:

Deploy your project to obtain a publicly accessible path to the OG image API endpoint. You can find an example deployment at https://og-examples.vercel.sh/api/static.

Then, based on the Open Graph Protocol, create the web content for your social media post as follows:

  • Create a tag inside the of the webpage
  • Add the attribute with value to the tag
  • Add the attribute with value as the absolute path of the endpoint to the tag

With the example deployment at https://og-examples.vercel.sh/api/static, use the following code:

Every time you create a new social media post, you need to update the API endpoint with the new content. However, if you identify which parts of your will change for each post, you can then pass those values as parameters of the endpoint so that you can use the same endpoint for all your posts.

In the examples below, we explore using parameters and including other types of content with .

  • Dynamic title: Passing the image title as a URL parameter
  • Dynamic external image: Passing the username as a URL parameter to pull an external profile image for the image generation
  • Emoji: Using emojis to generate the image
  • SVG: Using SVG embedded content to generate the image
  • Custom font: Using a custom font available in the file system to style your image title
  • Tailwind CSS: Using Tailwind CSS (Experimental) to style your image content
  • Internationalization: Using other languages in the text for generating your image
  • Secure URL: Encrypting parameters so that only certain values can be passed to generate your image
  • Recommended OG image size: 1200x630 pixels
  • uses Satori and Resvg to convert HTML and CSS into PNG
  • API reference
  • Only , , and font formats are supported. To maximize the font parsing speed, or are preferred over
  • Only flexbox () and a subset of CSS properties are supported. Advanced layouts () will not work. See Satori's documentation for more details on supported CSS properties
  • Maximum bundle size of 500KB. The bundle size includes your JSX, CSS, fonts, images, and any other assets. If you exceed the limit, consider reducing the size of any assets or fetching at runtime

Was this helpful?

supported.