Skip to content

HTML to image converter

Paste HTML and CSS, preview it live, then download the image or copy a URL that renders a new one for every value you pass.

⌘/Ctrl + Enter to generate
Image settings
Live preview. Generate to render it in Chrome.

Generate it on demand

Put the URL in an img tag or an og:image. Change a value in the URL and the API renders a new image.

Variables

Image URL

How to convert HTML to an image

Paste your HTML

Paste HTML with its CSS, or start from a template. Write {{title}} where a value changes. The live preview updates as you type.

Set the size

Pick a social size like Open Graph, X or Instagram, 1x or 2x pixel density, and PNG or JPG.

Generate

Microlink renders the HTML and CSS in a real Chrome browser and returns the image.

Download or embed

Save the image, or copy its URL. Change a value in the URL and the API renders a new image.

HTML to image API

The image URL is one API call. scripts writes your HTML into the page and fills it from the url, screenshot captures it, and embed answers with the image itself.

The following examples show how to use the Microlink API with cURL, JavaScript, Python, Ruby, PHP & Golang, targeting 'https://example.com/?title=Hello%20from%20the%20URL' URL with 'scripts', 'viewport', 'screenshot', 'meta' & 'embed' API parameters:

cURL Microlink API example

curl -G "https://api.microlink.io" \
  -d "url=https%3A%2F%2Fexample.com%2F%3Ftitle%3DHello%2520from%2520the%2520URL" \
  -d "scripts=document.body.innerHTML%20%3D%20'%3Ch1%20style%3D%22font%3A%2072px%20system-ui%22%3E%3C%2Fh1%3E'%3B%20document.querySelector('h1').textContent%20%3D%20new%20URLSearchParams(location.search).get('title')" \
  -d "viewport.width=1200" \
  -d "viewport.height=630" \
  -d "screenshot=true" \
  -d "meta=false" \
  -d "embed=screenshot.url"

JavaScript Microlink API example

import createClient from 'microlink.io'

const microlink = createClient()

const data = await microlink.screenshot('https://example.com/?title=Hello%20from%20the%20URL', {
  scripts: "document.body.innerHTML = '<h1 style=\"font: 72px system-ui\"></h1>'; document.querySelector('h1').textContent = new URLSearchParams(location.search).get('title')",
  viewport: {
    width: 1200,
    height: 630
  }
})

Python Microlink API example

import requests

url = "https://api.microlink.io/"

querystring = {
    "url": "https://example.com/?title=Hello%20from%20the%20URL",
    "scripts": '''document.body.innerHTML = '<h1 style="font: 72px system-ui"></h1>'; document.querySelector('h1').textContent = new URLSearchParams(location.search).get('title')''',
    "viewport.width": "1200",
    "viewport.height": "630",
    "screenshot": "true",
    "meta": "false",
    "embed": "screenshot.url"
}

response = requests.get(url, params=querystring)

print(response.content)

Ruby Microlink API example

require 'uri'
require 'net/http'

base_url = "https://api.microlink.io/"

params = {
  url: "https://example.com/?title=Hello%20from%20the%20URL",
  scripts: 'document.body.innerHTML = \'<h1 style="font: 72px system-ui"></h1>\'; document.querySelector(\'h1\').textContent = new URLSearchParams(location.search).get(\'title\')',
  "viewport.width": "1200",
  "viewport.height": "630",
  screenshot: "true",
  meta: "false",
  embed: "screenshot.url"
}

uri = URI(base_url)
uri.query = URI.encode_www_form(params)

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Get.new(uri)
response = http.request(request)

puts response.body

PHP Microlink API example

<?php

$baseUrl = "https://api.microlink.io/";

$params = [
    "url" => "https://example.com/?title=Hello%20from%20the%20URL",
    "scripts" => 'document.body.innerHTML = \'<h1 style="font: 72px system-ui"></h1>\'; document.querySelector(\'h1\').textContent = new URLSearchParams(location.search).get(\'title\')',
    "viewport.width" => "1200",
    "viewport.height" => "630",
    "screenshot" => "true",
    "meta" => "false",
    "embed" => "screenshot.url"
];

$query = http_build_query($params);
$url = $baseUrl . '?' . $query;

$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET"
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error #: " . $err;
} else {
    echo $response;
}

Golang Microlink API example

package main

import (
    "fmt"
    "net/http"
    "net/url"
    "io"
)

func main() {
    baseURL := "https://api.microlink.io"

    u, err := url.Parse(baseURL)
    if err != nil {
        panic(err)
    }
    scriptsParam := `document.body.innerHTML = '<h1 style="font: 72px system-ui"></h1>'; document.querySelector('h1').textContent = new URLSearchParams(location.search).get('title')`

    q := u.Query()
    q.Set("url", "https://example.com/?title=Hello%20from%20the%20URL")
    q.Set("scripts", scriptsParam)
    q.Set("viewport.width", "1200")
    q.Set("viewport.height", "630")
    q.Set("screenshot", "true")
    q.Set("meta", "false")
    q.Set("embed", "screenshot.url")
    u.RawQuery = q.Encode()

    req, err := http.NewRequest("GET", u.String(), nil)
    if err != nil {
        panic(err)
    }

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, err := io.ReadAll(resp.Body)
    if err != nil {
        panic(err)
    }

    fmt.Println(string(body))
}

Questions

How do I convert HTML to an image?

Paste your HTML and CSS into the editor, or start from a template. Pick a size and PNG or JPG, and press Generate. When the image appears, press Download to save it, or copy its image URL.

Is the HTML to image converter free?

Yes. Each image is one Microlink API request: 5 per day without an account, 25 per day with a free one. No login and no watermark.
Need more? Sign in or pick a plan and the same page runs on your account.

Which formats and sizes can I export?

PNG and JPG, at the sizes social networks use: Open Graph, X post, LinkedIn post, Instagram square, Instagram portrait, Story, YouTube thumbnail and Pinterest pin. At 2x pixel density a 1200 by 630 card exports at 2400 by 1260 for sharp results on high density screens. Turn on Fit height to capture the whole page at the chosen width.

What size should an Open Graph image be?

1200 × 630 pixels, a ratio of about 1.9:1. It is the size Facebook, LinkedIn, Slack and most chat apps use for link previews. Keep the title and logo away from the edges, since some apps crop the sides. Pick Open Graph in the size menu and generate at 2x for a 2400 × 1260 image that stays sharp on high density screens.

Can I make Open Graph images with it?

Yes. Start from one of the Open Graph templates, change the text and colors, and copy the image URL. Set it as the og:image of your page, with the title of that page in the URL, and every page gets its own image.

How do I make one image per page from a template?

Write {{name}} where a value changes, like {{title}} or {{author}}. Each one becomes a field under the editor and a parameter of the image URL. Change it in the URL and the API renders a new image, so one template covers every blog post, product or user. A value you leave out keeps the one you set in the tool.

Does JavaScript in my HTML run?

Yes. The HTML is loaded in a real Chrome browser, so inline scripts run before the image is taken, the same as in the live preview.

How much HTML can I convert?

The HTML is compressed and sent in the request, so a typical page or card fits. Large images or fonts written inline as base64 can make it too big: link them by URL instead.

Can I convert HTML to an image from my code?

Yes. The image URL is a plain GET request to the Microlink API that answers with the image itself, thanks to the embed parameter, so it works from any language, an img tag or a meta tag. To fill it from your code, set your values in the url parameter of that URL.

Who sees the HTML I paste?

Your HTML is sent to the Microlink API to be rendered, like any other API request. Do not paste passwords, API keys or personal data into it.

Other questions?

We’re always available at hello@microlink.io.