Social images and icons
What you need to know
Social preview images and icons are metadata assets served through Next.js file conventions. A predictable image, dimensions and descriptive alternative text make link previews clearer.
By the end, you can: choose file conventions; specify content type and accessible metadata.
Generate an original social card
import {ImageResponse} from 'next/og';export const alt='River Books reading guides';export const size={width:1200,height:630};export const contentType='image/png';export default function Image(){ return new ImageResponse(<div style={{display:'flex',width:'100%',height:'100%',background:'#153c39',color:'white',alignItems:'center',justifyContent:'center',fontSize:64}}>River Books</div>,size);}Expected behavior: Place in app/opengraph-image.tsx or a segment. Expected PNG card with centered English title; rendering is staged.
How it works
Use opengraph-image and twitter-image files or dynamic image modules at the relevant route segment. Next.js derives metadata for recognized files; verify precedence against explicitly configured images. For dynamic generation import ImageResponse from next/og, return an image response, and choose a supported layout subset, such as flexbox. This is not a full browser CSS engine; advanced CSS and unsupported fonts may differ. Keep rendering bounded, avoid remote asset fetches from user input, and supply local reviewed artwork or default fonts where appropriate. Icon and apple-icon conventions provide browser or device icons, distinct from social previews. A social image may be cached, and platforms may cache previews independently; retesting must distinguish the actual image endpoint from a social platform preview. Use an original text-based graphic rather than protected covers. Test image response status, content type, dimensions and rendered text. The example uses only English text and no external network.
Generate a simple icon
import {ImageResponse} from 'next/og';export const size={width:64,height:64};export const contentType='image/png';export default function Icon(){return new ImageResponse(<div style={{display:'flex',width:'100%',height:'100%',background:'#153c39',color:'white',alignItems:'center',justifyContent:'center',fontSize:40}}>R</div>,size);}Expected behavior: Place in app/icon.tsx. Expected 64 by 64 PNG with an R; inspect the emitted icon link.
Common mistake
Do not assume an ImageResponse supports every CSS property. Avoid arbitrary remote image inputs and do not infer actual output from the TypeScript syntax check.
Practice and verification
Inspect the generated Open Graph URL, image dimensions, contrast and alternative text after a reviewed production build. Compare browser icon and social-card purpose.
Scope: Proposed Next.js 16.x / React 19, Cache Components disabled unless noted. Framework and browser examples are staged; local standalone tests are reported separately. Exact dependency patches and platform contracts pending.
Further reading: Og · Image Response · Icons