Documentation
Quick Start Guide
Get started with HTML to Image API in minutes. Follow these simple steps to begin converting HTML to images or taking screenshots.
1. Get Your API Key
Sign up for an API key at app.html2img.com. Your API key will be used to authenticate all requests to our service.
Keep your API key secure and never expose it in client-side code. Use environment variables or server-side configuration to store your key.
2. Choose Your API Endpoint
We provide two main API endpoints:
-
HTML/CSS API - Convert raw HTML to images:
POST https://app.html2img.com/api/html
-
Screenshot API - Capture screenshots of any URL:
POST https://app.html2img.com/api/screenshot
All requests require your API key in the X-API-Key
header:
X-API-Key: your_api_key_here
3. Make Your First Request
Here’s a simple example using JavaScript to convert HTML to an image:
const response = await fetch('https://app.html2img.com/api/html', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'YOUR_API_KEY'
},
body: JSON.stringify({
html: '<div style="padding: 20px; background: #f0f0f0;">Hello, World!</div>',
width: 800,
height: 600
})
});
const imageBuffer = await response.buffer();
// For Node.js:
await fs.writeFile('output.png', imageBuffer);
// For browser:
const imageBlob = await response.blob();
4. Explore Features
The API supports various features and options:
- Custom Dimensions: Set width and height
- DPI Control: Adjust image quality with DPI
- Screenshot Mode: Capture full webpage screenshots
- CSS Injection: Add custom styles
See our parameters reference for a complete list of options.
5. Choose Your Integration
We provide examples and libraries for various languages and frameworks:
Of course, because this is a REST API, you can use any language or framework you prefer.
See our usage guide for detailed integration instructions.
6. Configure Options
Customize your image generation with parameters:
{
"html": "<div>Your HTML content</div>",
"css": "body { background: #fff; }",
"width": 800,
"height": 600
}
Next Steps
- Review our usage examples for your preferred language
- Learn about all available parameters
- Check out example use cases
Need help? Our support team is available 24/7 to assist with your integration.