developer template

Code Screenshot API

Beautiful syntax-highlighted code screenshots with window chrome

Code Screenshot template preview, a developer image generated by the html2img API

Use cases for the Code Screenshot API

The Code Screenshot template is the shortest path to a working code screenshot api from your stack. Send a small JSON payload, get back a tested PNG that fits your brand. No browser, no headless Chrome wrangling, no design tooling on your side.

Common reasons people reach for this template:

  • Code share images for X/LinkedIn
  • Documentation and tutorial hero images
  • Release note snippets

How it works

1

Send a JSON payload

POST to the template endpoint with the values you want rendered. Authenticate with your API key.

2

We render the image

The template is rendered server-side as a 1200x630 PNG (or whatever dimensions the template defines).

3

You get back a URL

The response includes a CDN URL for the PNG. Cache it, embed it, attach it to a tweet, anything you need.

Quick example

A single cURL call to render a Code Screenshot as a PNG:

curl -X POST https://app.html2img.com/api/v1/templates/code-screenshot \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"code":"export async function fetchUser(id: string) {\n  const res = await fetch(`/api/users/${id}`);\n\n  if (!res.ok) {\n    throw new Error(`Failed to load user ${id}`);\n  }\n\n  return res.json() as Promise<User>;\n}","language":"typescript","title":"src/lib/users.ts","theme":"github-dark","background":"linear-gradient(135deg, #6366F1 0%, #8B5CF6 50%, #EC4899 100%)","padding":72,"show_window_chrome":"true","show_line_numbers":"false"}'

For the full PHP, Node and Python equivalents, plus every input the template accepts, see the Code Screenshot API reference. Setting up your key is covered in the authentication guide.

Inputs at a glance

A quick summary of what the Code Screenshot template accepts. The full reference, including example values and array shapes, is in the docs.

Name Type Required
code string Required
language string Optional
title string Optional
theme string Optional
background string Optional
padding number Optional
show_window_chrome enum Optional
show_line_numbers enum Optional

See the full inputs reference for descriptions, examples and validation rules.

Related templates

Ready to render your first Code Screenshot?

Sign up free, grab an API key, send a payload. The pricing page covers the higher-volume plans if you outgrow the free tier.