October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk8 min

How to Generate Open Graph Images with HTML

Turn an HTML/CSS card design into a crawlable social preview image, connect it with Open Graph metadata, and troubleshoot rendering and preview issues.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To generate an Open Graph image with HTML, build a social-card layout, render it as an image through a server-side endpoint, and point your page’s og:image metadata to that publicly accessible image URL. For a Vercel-based implementation, @vercel/og turns supported HTML-like JSX and CSS into PNG; for arbitrary existing HTML or full browser behavior, use a browser screenshot pipeline instead.

How HTML becomes an Open Graph image

HTML is the design input, not the image that social platforms display. A renderer must turn the layout into a PNG or another supported image format, and your page must identify that image in its metadata. The Open Graph Protocol describes its purpose this way: “The Open Graph protocol enables any web page to become a rich object in a social graph.” Its basic metadata model includes a title, type, canonical URL, description, and image URL. Open Graph Protocol.

  1. Create a reusable card design with a fixed canvas and content such as a title, brand mark, or author name.
  2. Render that design at a server-side image route, or render a dedicated HTML page in a browser and capture it.
  3. Return an image response and make the route available to social crawlers.
  4. Add an absolute URL for that image to the page’s og:image tag.
  5. Inspect the deployed page and image, not just the local template.

Vercel’s documentation recommends a 1200 × 630-pixel image for an OG card. That is Vercel’s recommendation, not a universal requirement for every social service. Vercel’s Open Graph image generation guide.

Choose a rendering approach

Use @vercel/og for supported, purpose-built card layouts

Vercel says @vercel/og uses Satori and Resvg to convert HTML and CSS into PNG. It is a convenient fit when the card can be built from the renderer’s supported subset of layout and styling features, and when you want an image route integrated with a Vercel Function. It is not a full browser: designs that depend on unsupported CSS or browser behavior must be simplified or rendered another way. Vercel’s guide and the API reference cover the documented behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Use a browser screenshot pipeline for existing pages or browser-dependent layouts

A browser-based approach opens an HTML page in a browser engine and captures the rendered result. Vercel’s 2022 announcement describes its earlier OG image service as taking a screenshot of an HTML page in a serverless function, while its newer library uses the Satori and Resvg pipeline. These are distinct architectures, not evidence that one is universally faster or better. The practical choice depends on CSS fidelity, hosting and runtime, deployment complexity, whether you can reuse existing markup, and how you load fonts and other assets. The available sources do not establish a controlled current performance comparison. Vercel’s 2022 announcement.

Build a card with @vercel/og

Vercel’s guide says the package is already included in Next.js App Router projects; for other applicable projects, it gives pnpm i @vercel/og as the install command. The documented installation workflow requires Node.js 22 or newer, and the guide identifies Next.js 12.2.3 or newer for Next.js implementations. Software requirements can change, so check the current guide for your framework and deployment setup.

This minimal Next.js App Router route returns a generated PNG. Place it at app/api/og/route.tsx:

import { ImageResponse } from '@vercel/og';

export const runtime = 'edge';

export async function GET(request: Request) {
  const { searchParams } = new URL(request.url);
  const title = searchParams.get('title') ?? 'A useful page title';

  return new ImageResponse(
    (
      <div
        style={{
          width: '100%',
          height: '100%',
          display: 'flex',
          flexDirection: 'column',
          justifyContent: 'center',
          padding: '72px',
          background: '#111827',
          color: 'white',
          fontSize: 64,
          fontWeight: 700,
        }}
      >
        <div style={{ fontSize: 24, color: '#93c5fd', marginBottom: 24 }}>
          EXAMPLE SITE
        </div>
        <div>{title}</div>
      </div>
    ),
    { width: 1200, height: 630 }
  );
}

In JSX source, the tags above should be ordinary JSX tags; the escaped angle brackets are shown only so the example can be carried safely in HTML. The route reads a title from a query parameter and supplies it as text, rather than injecting it as markup. Vercel’s API reference lists width and height parameters with defaults of 1200 and 630, PNG output, and default cache headers. Set dimensions explicitly when your design depends on that canvas. API reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Connect the image route to page metadata

Place an absolute URL to the generated route in the page’s head. For example:

<meta property="og:title" content="A useful page title">
<meta property="og:type" content="website">
<meta property="og:url" content="https://example.com/articles/useful-page">
<meta property="og:description" content="A concise description of the page.">
<meta property="og:image" content="https://example.com/api/og?title=A%20useful%20page%20title">

Encode dynamic query values when constructing URLs. In a framework, prefer its metadata API or a URL builder so titles containing spaces, ampersands, or non-ASCII characters are represented correctly. The important requirement is that crawlers receive the metadata in the page’s HTML response and can fetch the absolute image URL. Open Graph Protocol.

Design within renderer constraints

Layout and CSS

Vercel documents basic flexbox and absolute positioning support, but CSS Grid is not supported by the OG renderer. Use nested flex containers, fixed spacing, and explicit dimensions instead of relying on a browser’s full CSS engine. If a composition uses complex responsive behavior, grid-specific placement, or intricate effects, simplify it for the image canvas or choose a browser screenshot workflow.

Fonts and assets

The guide lists TTF, OTF, and WOFF as custom font formats, with TTF and OTF preferred for font parsing speed. Bundle only the fonts and images the card needs. Vercel documents a 500 KB maximum bundle size, including JSX, CSS, fonts, images, and other assets; a large typeface or decorative asset can consume that budget quickly. Keep a fallback font strategy and verify that the deployed route can load every external asset it references. Vercel’s guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Dynamic content and safety

  • Use a predictable fallback title when a query parameter or page field is missing.
  • Escape or pass dynamic content as text; do not treat user-controlled titles as markup.
  • Keep the title length bounded and design for wrapping or truncation so long headings do not overflow.
  • Use deterministic output for the same page data where possible, which makes caching useful and avoids changing previews unexpectedly.
  • Do not assume a social crawler will execute client-side scripts or have access to authenticated assets. Make the image route and required assets fetchable without a user session.

Make the generated image crawlable and verify deployment

A working local image route is only one part of the result. The deployed page must expose the correct raw metadata, and the image URL must respond to requests from outside your browser. Vercel recommends allowing the OG API route in robots.txt so social providers can fetch it; this is a crawler-access consideration, not a guarantee that every service will render or refresh a preview identically. Vercel’s guide.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
  1. Deploy the route and open its absolute URL directly. Confirm the response is an image and that the image has the intended dimensions and content.
  2. View the deployed page’s raw HTML or response source. Confirm there is one relevant og:image value and that it is an absolute, correctly encoded URL.
  3. Check the deployed site’s robots.txt and ensure it does not disallow the image route if social crawlers need to fetch it.
  4. Use Vercel’s deployment Open Graph inspection feature to inspect metadata and preview renders for Twitter, Slack, Facebook, and LinkedIn. Vercel’s Open Graph inspection guide.
  5. If the preview remains stale, separate a renderer issue from crawler access or cached metadata: test the image URL itself, inspect the page head, then use the platform’s available refresh or inspection process.

Preview fetching and cache behavior can vary by platform. A successful direct browser load proves the route works for your browser, but does not prove that every crawler can access it or that a previously cached card will refresh immediately.

Troubleshoot common failures

Symptom Likely cause What to check or change
The route fails to build or render Unsupported CSS, incompatible runtime assumptions, missing dependency, or a package/framework version mismatch. Compare the project’s runtime and framework with Vercel’s current requirements; reduce the card to supported flexbox or absolute-positioned layout and inspect deployment logs.
The card looks different from the HTML page @vercel/og is not a full browser and does not support every CSS feature. Replace grid-based or browser-dependent styling with supported layout, or use a browser screenshot pipeline when fidelity to existing markup is essential.
Font is missing or text wraps badly The font asset is unavailable to the route, in an unsupported format, too large for the bundle, or not loaded as expected. Use a supported TTF, OTF, or WOFF file, prefer TTF/OTF per Vercel’s guidance, reduce asset weight, and test with fallback fonts and long titles.
The image URL shows an error or blank output Bad query encoding, a runtime exception, missing assets, or a route that requires authentication. Open the exact deployed URL, inspect its HTTP response and logs, encode dynamic query values, and remove session-only dependencies.
The page has no social image The metadata is absent from the crawler-visible HTML, the URL is relative or malformed, or crawler access is blocked. Inspect the raw deployed head for an absolute og:image, test the endpoint publicly, and check robots rules.
The preview shows an old image A social service may be serving cached metadata or an earlier image response. Confirm the current page and image URL independently, then use that platform’s preview inspection or refresh mechanism where available.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your do-it-yourself design is already an HTML page, a browser capture can turn that rendered page into an image without building a custom screenshot setup. ScreenshotNeo is a website screenshot API and MCP server for developers; its API accepts a URL and returns a PNG, JPEG, WebP, or PDF. A simple request is:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com/og-card -o og-card.webp

See the ScreenshotNeo API documentation for request options. Cookie banners, popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed. An MCP server lets AI agents use screenshot tools, and the free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. For Open Graph use, make sure the captured page is a public, purpose-built card URL and that the returned image is publicly fetchable before using it in metadata. Learn about ScreenshotNeo, or sign up free for 1,000 screenshots a month with no card.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Frequently Asked Questions

Does an Open Graph image have to be generated dynamically?

No. You can generate an image at build time or use a static image URL; dynamic rendering is useful when card content varies by page or changes with data.

Can I use an HTML page directly as the value of og:image?

No. The metadata should point to an image URL that returns an image, not to the HTML design page itself.

Does setting og:image guarantee the same preview on every social platform?

No. Crawling, image handling, and cached-preview refresh behavior vary by service.

Quick Recap

SaleBestseller No. 1
HTML and CSS: Design and Build Websites
HTML and CSS: Design and Build Websites
HTML CSS Design and Build Web Sites; Comes with secure packaging; It can be a gift option
$14.18
SaleBestseller No. 3
SaleBestseller No. 4
Web Design with HTML, CSS, JavaScript and jQuery Set
Web Design with HTML, CSS, JavaScript and jQuery Set
Brand: Wiley; Set of 2 Volumes
$35.05

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.