Link Search Menu Expand Document

GoLang: HTML/CSS to Image

Generate a png, jpg or webp images with GoLang. Renders exactly like Google Chrome.

Live demo Get an API Key

Table of contents

Generating images with GoLang

  1. The API takes your HTML/CSS and runs it inside a real instance of Google Chrome to convert your html into an image.
  2. Use GoLang to send the API your HTML/CSS.
  3. You’ll get back json with the URL to your generated image.

For more details on how this works, see Creating an image.

Example API response:

  "url": ""

Image generated with GoLang. Convert HTML to an image using GoLang.

Authentication with GoLang

The API uses HTTP Basic authentication.

Your username is your User ID and your password is your API Key. Both of these are available from the dashboard. The GoLang code sample demonstrates how to authenticate your request.

You can signup for a free API key to get started.

Free API Key for GoLang

GoLang example code

This GoLang code example sends an HTTP POST to the API. Converting your HTML/CSS to an image with GoLang.

package main
import (
const (
    userID = "your_user_id"
    apiKey = "your_api_key"
func main() {
    data := map[string]string{
        "html": "<div class='ping'>Pong ✅</div>",
        "css":  ".ping { padding: 20px; font-family: 'sans-serif'; }",
    reqBody, err := json.Marshal(data)
    if err != nil {
        log.Fatalf("unable to marshal data: %s", err.Error())
    req, err := http.NewRequest("POST", "", bytes.NewReader(reqBody))
    if err != nil {
        log.Fatalf("unable to create new request: %s", err.Error())
    req.SetBasicAuth(userID, apiKey)
    client := &http.Client{Timeout: time.Second * 10}
    resp, err := client.Do(req)
    if err != nil {
        log.Fatalf("request was unsuccessful: %s", err.Error())
    defer resp.Body.Close()
    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        log.Fatalf("unable to read response body: %s", err.Error())

    // {"url":""}

Need help?

We’re always looking to improve this documentation. Please send us an email: We respond fast.

Back to top

Built with extensive integration tests and serious care for developer happiness.
© 2018-2024 Code Happy, LLC.

Page last modified: Apr 9 2024 at 11:04 PM.

Edit this page on GitHub.