npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

satori

v0.63.2

Published

Enlightened library to convert HTML and CSS to SVG.

Readme

Satori

Satori: Enlightened library to convert HTML and CSS to SVG.

Note

To use Satori in your project to generate PNG images like Open Graph images and social cards, check out our announcement and Vercel’s Open Graph Image Generation docs →

To use it in Next.js, take a look at the Open Graph Image Generation examples →

Overview

Satori supports the JSX syntax, which makes it very straightforward to use. Here’s an overview of the basic usage:

// api.jsx
import satori from 'satori'

const svg = await satori(
  <div style={{ color: 'black' }}>hello, world</div>,
  {
    width: 600,
    height: 400,
    fonts: [
      {
        name: 'Roboto',
        // Use `fs` (Node.js only) or `fetch` to read the font as Buffer/ArrayBuffer and provide `data` here.
        data: robotoArrayBuffer,
        weight: 400,
        style: 'normal',
      },
    ],
  },
)

Satori will render the element into a 600×400 SVG, and return the SVG string:

'<svg ...><path d="..." fill="black"></path></svg>'

To render it to a PNG, use Sharp, which draws SVG with librsvg:

import sharp from 'sharp'

const png = await sharp(Buffer.from(svg)).png().toBuffer()

Under the hood, it handles layout calculation, font, typography and more, to generate a SVG that matches the exact same HTML and CSS in a browser.

Documentation

JSX

Satori only accepts JSX elements that are pure and stateless. You can use a subset of HTML elements (see section below), or custom React components, but React APIs such as useState and useEffect are not supported, and dangerouslySetInnerHTML is only supported on <style> and <script>.

Experimental: builtin JSX support

Satori has an experimental JSX runtime that you can use without having to install React. You can enable it on a per-file basis with @jsxImportSource pragmas. In the future, it will autocomplete only the subset of HTML elements and CSS properties that Satori supports for better type-safety.

/** @jsxRuntime automatic */
/** @jsxImportSource satori/jsx */

import satori from 'satori';
import { FC, JSXNode } from 'satori/jsx';

const MyComponent: FC<{ children: JSXNode }> = ({ children }) => (
  <div style={{ color: 'black' }}>{children}</div>
)

const svg = await satori(
  <MyComponent>hello, world</MyComponent>,
  options,
)

Use without JSX

If you don't have JSX transpiler enabled, you can simply pass React-elements-like objects that have type, props.children and props.style (and other properties too) directly:

await satori(
  {
    type: 'div',
    props: {
      children: 'hello, world',
      style: { color: 'black' },
    },
  },
  options
)

HTML Elements

Satori supports a limited subset of HTML and CSS features, due to its special use cases. In general, only these static and visible elements and properties that are implemented.

For example, the cursor CSS property is not in consideration. Text inputs show their value or placeholder, styled with ::placeholder, button inputs their label, and selects their selected option, or their options with multiple or size, but other form controls have no content. <style> elements apply their CSS, see Stylesheets, but external resources via <link> or <script> aren't loaded.

Also, Satori does not guarantee that the SVG will 100% match the browser-rendered HTML output since Satori implements its own layout engine based on the SVG 1.1 spec.

You can find the list of supported HTML elements and their preset styles here.

Images

You can use <img> to embed images. However, width, and height attributes are recommended to set:

await satori(
  <img src="https://picsum.photos/200/300" width={200} height={300} />,
  options
)

When using background-image, the image will be stretched to fit the element by default if you don't specify the size.

If you want to render the generated SVG to another image format such as PNG, it would be better to use base64 encoded image data (or buffer) directly as props.src so no extra I/O is needed in Satori:

await satori(
  <img src="data:image/png;base64,..." width={200} height={300} />,
  // Or src={arrayBuffer}, src={buffer}
  options
)

Canvas (WebGL, experimental)

Note: This is experimental and may change or be removed in any release. It's only available from satori/experimental, so it doesn't add to the size of the satori import.

With satori/experimental, you can draw the content of a <canvas> with WebGL2 via the webgl prop. Satori calls it with a WebGL2 context sized to the canvas, then embeds what you drew as an image:

import satori from 'satori/experimental'

await satori(
  <canvas
    width={1200}
    height={630}
    style={{ width: '100%', height: '100%' }}
    webgl={(gl, { width, height }) => {
      gl.clearColor(0, 0.5, 1, 1)
      gl.clear(gl.COLOR_BUFFER_BIT)
      // Compile shaders, draw, etc.
    }}
  />,
  options
)

Each canvas gets a new WebGL2 context, which is destroyed with everything drawn into it afterwards:

  • In browsers and Web Workers, Satori uses OffscreenCanvas.
  • In Node.js 20.16+, Satori loads the gl package from your project, which must be a WebGL2 build of headless-gl such as an ANGLE + SwiftShader one (e.g. github:encharm/headless-gl). It runs shaders on the CPU. If you bundle your server code, keep gl external and include its files in the deployment.

To provide contexts yourself, e.g. to reuse them across renders, pass a createWebGLContext(width, height) option that returns a WebGL2 context. Satori doesn't destroy the contexts it returns.

  • The width and height attributes set the drawing buffer size (300×150 by default), like in browsers. The canvas is displayed at its CSS size, keeping that aspect ratio unless both CSS dimensions are set.
  • Before calling webgl, Satori binds the default framebuffer, sets the viewport to the whole drawing buffer, and clears it to transparent, like a new canvas. Afterwards, it reads the default framebuffer. The webgl callback can be async.
  • The drawing buffer is treated as premultiplied alpha unless the context was created with premultipliedAlpha: false.
  • Children of <canvas> are fallback content and are not rendered.
  • The satori import ignores the webgl prop and draws <canvas> like any other element.

If you use React's JSX types, add the webgl prop to them:

import type { WebGLCanvasRenderer } from 'satori/experimental'

declare module 'react' {
  interface CanvasHTMLAttributes<T> {
    webgl?: WebGLCanvasRenderer
  }
}

CSS

Satori uses Taffy to lay out Flexbox, Grid and block layouts, and its own inline layout for text and inline elements. It’s not a complete CSS implementation, but it supports most common CSS features. Properties marked “Supported” behave as in browsers; otherwise, the differences are listed:

Note:

  1. In 3D transforms, elements in a preserve-3d context are drawn back to front by the depth of their centers, and elements that intersect aren't cut where they cross. Perspective is approximated: each element is drawn with the affine transform closest to it around its center, which is exact for elements facing the viewer, such as translateZ(). satori/experimental draws perspective exactly.
  2. Percentages in calc(), min(), max() and clamp() only work in sizes, margins, paddings, insets, gaps, flexBasis and translations. Elsewhere, values with them are ignored.
  3. Properties that aren't listed are ignored, for example columns, writingMode and fontStretch.
  4. Invalid values in inline styles throw an error, which fails the whole render, unless they're ignored with onStyleError. Stylesheets drop them instead, see Stylesheets.
  5. inherit on properties that aren't inherited, e.g. border: inherit, sets their initial value instead of the value of the parent.

Stylesheets

The CSS of <style> elements applies to the whole tree, including the elements of components. The declarations of matching rules are merged with inline styles in cascade order, so the table above applies to them too. Selectors, specificity, !important, nesting, @layer, @media, @supports, @container, @property and the media attribute are supported, with these differences:

  • @media matches the width and height of the image, on a static screen in light mode, e.g. prefers-color-scheme: light and hover: none.
  • @container supports size queries, but style() and scroll-state() queries don't match. Container units like cqw are supported, but in values of custom properties, they're of the viewport.
  • @property sets the initial values of custom properties and whether they're inherited, but values aren't checked or computed with its syntax.
  • Invalid and unsupported declarations are dropped like in browsers, and passed to onStyleError. Values with var() are only checked when they're computed, where invalid values throw like in inline styles.
  • @supports checks declarations the same way, but properties that Satori ignores count as supported. selector() is supported, but not font-tech() and font-format().
  • ::before and ::after are supported, with content made of strings, attr(), counter(), counters(), quotes and url(). Quotes are always “ and ”, as quotes isn't supported. Other pseudo-elements, such as ::marker and ::first-line, aren't supported, so rules with them don't apply.
  • Pseudo-classes of interactions such as :hover never match, and functional pseudo-classes other than :is(), :where(), :not(), :has(), :nth-*() and :lang() make their rule invalid.
  • Other at-rules are ignored, such as @font-face, @keyframes, @scope and @import.

Perspective (experimental)

Note: This is experimental and may change or be removed in any release. It's only available from satori/experimental, so it doesn't add to the size of the satori import.

With satori/experimental, perspective from the perspective property and the perspective() function is drawn exactly:

import satori from 'satori/experimental'

await satori(
  <div style={{ display: 'flex', perspective: 600 }}>
    <div style={{ display: 'flex', transform: 'rotateY(35deg)' }}>Hello</div>
  </div>,
  options
)

SVG has no perspective transforms, so each element with perspective is split into triangles that are each drawn with an affine transform, within 0.5px of the exact position. This makes the SVG larger and slower to render: depending on the angle, an element is drawn up to a few hundred times.

Language and Typography

OpenType Features: Satori supports advanced typography features via HarfBuzz text shaping. Use the font-feature-settings CSS property to enable OpenType features such as:

  • Ligatures (liga, dlig, hlig)
  • Small caps (smcp, c2sc)
  • Stylistic sets (ss01-ss20)
  • Contextual alternates (calt)
  • Swashes (swsh, cswh)
  • And many more OpenType features

Example:

<div style={{ fontFeatureSettings: '"smcp" 1, "liga" 0' }}>
  This Text Uses Small Caps
</div>

HarfBuzz also improves glyph shaping for complex scripts such as Arabic. Words are ordered with a simplified Unicode bidirectional algorithm, so right-to-left text in a left-to-right element, and left-to-right text and numbers in a right-to-left one, follow browser ordering, and lines with direction: rtl are laid out from the right. Explicit embeddings with unicodeBidi, bracket pairs and reordering text with inline elements in it aren't supported yet.

Fonts

Satori supports four font formats: TTF, OTF, WOFF and WOFF2. Variable fonts are rendered as their default instance, e.g. the regular weight. You must specify the font if any text is rendered with Satori, and pass the font data as ArrayBuffer (web) or Buffer (Node.js):

await satori(
  <div style={{ fontFamily: 'Inter' }}>Hello</div>,
  {
    width: 600,
    height: 400,
    fonts: [
      {
        name: 'Inter',
        data: inter,
        weight: 400,
        style: 'normal',
      },
      {
        name: 'Inter',
        data: interBold,
        weight: 700,
        style: 'normal',
      },
    ],
  }
)

Multiple fonts can be passed to Satori and used in fontFamily.

[!TIP] We recommend you define global fonts instead of creating a new object and pass it to satori for better performance, if your fonts do not change. Read it for more detail

Emojis

To render custom images for specific graphemes, you can use graphemeImages option to map the grapheme to an image source:

await satori(
  <div>Next.js is 🤯!</div>,
  {
    ...,
    graphemeImages: {
      '🤯': 'https://cdnjs.cloudflare.com/ajax/libs/twemoji/14.0.2/svg/1f92f.svg',
    },
  }
)

The image will be resized to the current font-size (both width and height) as a square.

Locales

Satori supports rendering text in different locales. You can specify the supported locales via the lang attribute:

await satori(
  <div lang="ja-JP">骨</div>
)

Same characters can be rendered differently in different locales, you can specify the locale when necessary to force it to render with a specific font and locale. Check out this example to learn more.

Supported locales are exported as the Locale enum type.

Dynamically Load Emojis and Fonts

Satori supports dynamically loading emoji images (grapheme pictures) and fonts. The loadAdditionalAsset function will be called when a text segment is rendered but missing the image or font:

await satori(
  <div>👋 你好</div>,
  {
    // `code` will be the detected language code, `emoji` if it's an Emoji, or `unknown` if not able to tell.
    // `segment` will be the content to render.
    loadAdditionalAsset: async (code: string, segment: string) => {
      if (code === 'emoji') {
        // if segment is an emoji
        return `data:image/svg+xml;base64,...`
      }

      // if segment is normal text
      return loadFontFromSystem(code)
    }
  }
)

Runtime Support

Satori can be directly used in browser, Node.js (>= 16), and Web Workers. It bundles its underlying WASM dependencies as base64-encoded strings and loads them at runtime.

If there is a limitation on dynamically loading WASM (e.g. Cloudflare Workers), you can use the Standalone Build which is mentioned below.

Standalone Build of Satori

Satori's standalone build doesn't include the WASM binary of its layout engine by default, and you need to load it manually before using Satori.

First, you need to download the layout.wasm binary from Satori build and provide it yourself. Let's use fetch to load it directly from the CDN as an example:

import satori, { init } from 'satori/standalone'

const res = await fetch('https://unpkg.com/satori/layout.wasm')
const layoutWasm = await res.arrayBuffer()

await init(layoutWasm)

// Now you can use satori as usual
const svg = await satori(...)

Of course, you can also load the layout.wasm file from your local disk via fs.readFile in Node.js or other methods.

Font Embedding

By default, Satori renders the text as <path> in SVG, instead of <text>. That means it embeds the font path data as inlined information, so succeeding processes (e.g. render the SVG on another platform) don’t need to deal with font files anymore.

You can turn off this behavior by setting embedFont to false, and Satori will use <text> instead:

const svg = await satori(
  <div style={{ color: 'black' }}>hello, world</div>,
  {
    ...,
    embedFont: false,
  },
)

Pixel Grid Rounding

Set pointScaleFactor to control how layout values are rounded to the pixel grid: they are rounded to multiples of 1 / pointScaleFactor px, or not rounded with 0. It defaults to 1, and higher values improve rendering precision on high-DPI displays. The width of text is rounded up the same way, so that it fits.

const svg = await satori(
  <div style={{ color: 'black' }}>hello, world</div>,
  {
    ...,
    pointScaleFactor: 2,
  },
)

Invalid Styles

By default, an invalid or unsupported declaration in an inline style throws an error, which fails the whole render. With onStyleError, the declaration is ignored instead, and its error is passed to the callback. Declarations of stylesheets are always dropped, like in browsers, and passed to the callback too:

const svg = await satori(
  <div style={{ display: 'table', color: 'black' }}>hello, world</div>,
  {
    ...,
    onStyleError: (error) => console.warn(error.message),
  },
)

Colors

Satori converts the colors that SVG renderers may not support to rgb() and rgba(). Sharp, for example, draws most of them black. They are:

  • lab(), lch(), oklab(), oklch() and color();
  • color-mix(), light-dark() and relative colors like rgb(from red r g b / 50%);
  • hwb(), rebeccapurple, and rgb() and hsl() without commas, like rgb(255 0 0 / 50%).

To keep them as they're written, for an SVG renderer that supports them, set convertColors to false:

const svg = await satori(
  <div style={{ color: 'oklch(0.7 0.2 30)' }}>hello, world</div>,
  {
    ...,
    convertColors: false,
  },
)

Colors in gradients are converted either way. SVG interpolates gradients in sRGB, so Satori adds stops to gradients that are interpolated in another color space: those with a color space like linear-gradient(in oklch, red, blue), and those in Oklab by default because they have colors from lab(), lch(), oklab(), oklch(), color(), color-mix() or relative colors.

Debug

To draw the bounding box for debugging, you can pass debug: true as an option:

const svg = await satori(
  <div style={{ color: 'black' }}>hello, world</div>,
  {
    ...,
    debug: true,
  },
)

Contribute

You can use the Vercel OG Image Playground to test and report bugs of Satori. Please follow our contribution guidelines before opening a Pull Request.

Author