As developers, we spend hours crafting great content, but often overlook how it appears when shared on social media. Let's fix that with this practical guide to social share images (OG images).
Open Graph (OG) images are preview images that appear when your content is shared on social platforms.
They're your first impression in a crowded social feed.
Simple example: When you share your blog post on Twitter/LinkedIn, the large image that appears is the OG image.
Here's what you need to know for major platforms:
Facebook/LinkedIn:
- 1200 x 630px (1.91:1 ratio)
- Minimum: 600 x 315px
- Max file size: 8MB
Twitter:
- 1200 x 600px (2:1 ratio)
- Large card: 1200 x 600px
- Small card: 440 x 220px
Pro tip: Design for 1200 x 630px - it works well across all platforms.
Add these meta tags to your <head>
:
<!-- Basic OG Image -->
<meta property="og:image" content="https://yourdomain.com/og-image.png" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<!-- Twitter -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:image" content="https://yourdomain.com/og-image.png" />
❌ Using generic stock photos
✅ Custom graphics or branded templates
❌ Text too small/too much
✅ Large, scannable text
❌ Inconsistent branding
✅ Use templates with your brand elements
Test your OG images with these tools:
Why create OG images manually when you can automate? Some approaches:
DIY Solution:
// Using Node.js + Sharp
const sharp = require('sharp');
async function generateOG(text) {
return await sharp('template.png')
.resize(1200, 630)
.composite([{
input: Buffer.from(`<svg>...</svg>`),
top: 0,
left: 0,
}])
.png()
.toBuffer();
}
Vercel's OG Image Generation:
// pages/api/og.tsx
import { ImageResponse } from '@vercel/og';
export default function handler() {
return new ImageResponse(
(
<div style={{
background: 'white',
width: '100%',
height: '100%',
padding: '50px'
}}>
<h1>Hello OG Image</h1>
</div>
)
);
}
Want To Make This Easier?
I built gleam.so because I got tired of making OG images manually.
It's free to try, and I'd love your feedback:
Get 75% off all paid plans with code: PH75OFF
Happy coding! ✨
Found this helpful? Follow me on Twitter/X for more web dev tips.