Link Search Menu Expand Document

GoLang: HTML/CSS to Image

Generate Images and PDFs with GoLang. Renders exactly like Google Chrome.

Render PNG, JPG, or WebP images + PDFs with GoLang from HTML/CSS or reusable dynamic templates.

Live demo Get an API Key


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": "https://hcti.io/v1/image/be4c5118-fe19-462b-a49e-48cf72697a9d",
  "id": "be4c5118-fe19-462b-a49e-48cf72697a9d"
}

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 sign up 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 https://hcti.io/v1/image API to convert your HTML/CSS to an image.

package main
import (
    "bytes"
    "encoding/json"
    "fmt"
    "io/ioutil"
    "log"
    "net/http"
    "time"
)
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", "https://hcti.io/v1/image", 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())
    }
    fmt.Println(string(body))

    // {"url":"https://hcti.io/v1/image/f1e2762b-1f95-4f99-ab5d-0444b26dfd42"}
}

Need help?

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


Back to top

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

Page last modified: Jul 3 2026 at 08:23 PM.

Edit this page on GitHub.