defineTemplate
ThedefineTemplate helper is the core building block. It ensures type safety and validates your template at registration time.
Templates use a React-like JSX syntax (recommended) or return HTML strings. Both are converted to PNG via the rendering pipeline.
Save template files as
.tsx and set "jsx": "react-jsx" in your tsconfig.json.
You do not need React as a runtime dependency — OGify uses Satori’s JSX factory.defineTemplate
Helper function to define a template with type safety, including the full renderer
context (
params, width, height, isRTL, fonts, emojiProvider, scale).Renderer Context
Yourrenderer receives all render options plus params. Use these props to build dynamic layouts:
See Rendering Pipeline for the complete reference.
Styling
We use Satori under the hood, which supports a subset of CSS properties. For a complete list, see Styles.tw Prop (Tailwind-like)
Use the tw prop on JSX elements for utility classes. Combine with clsx for conditionals:
Inline Styles
Use thestyle prop for CSS properties not covered by utilities:
Inline HTML Styling
For styled words inside text, usehtmlSnippet:
HTML String Alternative
You can still return HTML strings fromrenderer. Classes on class are parsed via satori-html:
Dynamic Content
Your renderer receivesparams from renderToImage. Use JSX expressions to inject dynamic values:
Best Practices
Prefer JSX over HTML strings
Prefer JSX over HTML strings
JSX templates give you type safety, conditional rendering (
{condition ? ... : null}),
and composition without string interpolation.Keep it simple
Keep it simple
Satori is powerful but has limitations compared to a full browser engine.
Avoid complex CSS selectors or deeply nested absolute positioning.
Use display: flex
Use display: flex
Flexbox is the most reliable layout mode in Satori. Use the
tw prop with
flex, flex-col, items-center, justify-between, etc.Test with isRTL
Test with isRTL
Ensure your template handles RTL content gracefully if you plan to support
international audiences.
Features
Rendering Pipeline
How templates become PNG images
Caching
A smart caching layer to improve performance
Font Loader
Using Google Fonts or custom fonts
Emoji Loader
Rendering emojis in your templates
RTL Support
Right-to-left language support
Styles
Supported CSS properties