How to make Open Graph images with HTML and CSS
An Open Graph image decides how your link looks when it is shared. Building it in HTML and CSS makes it easy to keep every image consistent.
Updated · 5 min read
When someone shares a link in a chat app or social network, the platform looks for an image in your page metadata. A clear Open Graph image makes the link stand out, and it often decides whether people click. Designing it in HTML and CSS means you can reuse one template for every article.
Use the right size
The widely used size is 1200 by 630 pixels, a ratio of about 1.91 to 1. Platforms may crop the edges, so keep important text and logos away from the border. Make the type large, because the image is often shown small in a feed.
Design it as a template
Build a layout with a title, a site name and a short subtitle. Use a fixed width and height of 1200 by 630 and a clear background. Keep the title to two or three lines so it stays readable when scaled down.
<div class="og">
<p class="site">yourblog.com</p>
<h1>How we cut build times by 60%</h1>
<p class="meta">Engineering notes from the platform team</p>
</div>Export and upload the image
Export the layout as PNG for sharp text, or JPEG for a smaller file. Upload it to your site so it has a stable, public URL.
Add the meta tags
<meta property="og:title" content="How we cut build times by 60%" />
<meta property="og:description" content="Engineering notes from the platform team." />
<meta property="og:image" content="https://example.com/og/build-times.png" />
<meta name="twitter:card" content="summary_large_image" />Use an absolute URL for the image. After publishing, test the link with the sharing debugger of each platform, because they cache previews and may show an old image until you refresh them.
Generating one image per page
For a handful of pages, change the title in the template and export each one by hand. For hundreds of pages, automate it with a headless browser such as Puppeteer or Playwright, which can load the template with a different title and take a screenshot at 1200 by 630.
Open the OG image generator with a ready template
Open OG Image Generator