---
title: "Capture an Instagram Embed"
description: "Capture an Instagram embed as a PNG. Multi-language code and the embed-loading delay you need to set."
url: "https://html2img.com/docs/examples/instagram-post/"
---

# How to Capture an Instagram Embed as an Image

Render an Instagram post embed as a PNG. Useful for archiving posts, embedding in editorial content or printing.

> **Note**
>
> Want it faster? Use the [Instagram Square Post template](https://html2img.com/templates/instagram-square-post/) and skip the embed widget. Send caption text, image and brand colour as JSON.

## HTML and CSS

```html
<blockquote class="instagram-media"
            data-instgrm-captioned
            data-instgrm-permalink="https://www.instagram.com/p/POST_ID/"
            data-instgrm-version="14">
</blockquote>
<script async src="//www.instagram.com/embed.js"></script>
```

```css
body { margin: 0; padding: 16px; background: white; }
.instagram-media {
    margin: 0 auto !important;
    min-width: 326px !important;
    max-width: 550px !important;
    width: calc(100% - 2px) !important;
}
```

## ms_delay

Instagram's embed.js loads asynchronously. Use [ms_delay](https://html2img.com/docs/parameters/ms_delay/) of 1500ms minimum so the post and image render before capture.

## Code examples

### cURL

```bash
curl -X POST https://app.html2img.com/api/html \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<blockquote class=\"instagram-media\" data-instgrm-captioned data-instgrm-permalink=\"https://www.instagram.com/p/POST_ID/\" data-instgrm-version=\"14\"></blockquote><script async src=\"//www.instagram.com/embed.js\"></script>",
    "css": "body { margin: 0; padding: 16px; background: white; } .instagram-media { margin: 0 auto !important; min-width: 326px !important; max-width: 550px !important; width: calc(100% - 2px) !important; }",
    "width": 600,
    "height": 800,
    "ms_delay": 1500
  }'
```

### PHP

```php
$ch = curl_init('https://app.html2img.com/api/html');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => ['X-API-Key: ' . getenv('HTML2IMG_API_KEY'), 'Content-Type: application/json'],
    CURLOPT_POSTFIELDS => json_encode([
        'html' => '<blockquote class="instagram-media" data-instgrm-captioned data-instgrm-permalink="https://www.instagram.com/p/POST_ID/" data-instgrm-version="14"></blockquote><script async src="//www.instagram.com/embed.js"></script>',
        'css' => 'body { margin: 0; padding: 16px; background: white; } .instagram-media { margin: 0 auto !important; min-width: 326px !important; max-width: 550px !important; width: calc(100% - 2px) !important; }',
        'width' => 600, 'height' => 800, 'ms_delay' => 1500,
    ]),
]);
$url = json_decode(curl_exec($ch), true)['url'];
```

### Node.js

```javascript
const response = await fetch('https://app.html2img.com/api/html', {
  method: 'POST',
  headers: { 'X-API-Key': process.env.HTML2IMG_API_KEY, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    html: '<blockquote class="instagram-media" data-instgrm-captioned data-instgrm-permalink="https://www.instagram.com/p/POST_ID/" data-instgrm-version="14"></blockquote><script async src="//www.instagram.com/embed.js"></script>',
    css: 'body { margin: 0; padding: 16px; background: white; } .instagram-media { margin: 0 auto !important; min-width: 326px !important; max-width: 550px !important; width: calc(100% - 2px) !important; }',
    width: 600, height: 800, ms_delay: 1500,
  }),
});
const { url } = await response.json();
```

### Python

```python
import os, requests
response = requests.post(
    'https://app.html2img.com/api/html',
    headers={'X-API-Key': os.environ['HTML2IMG_API_KEY']},
    json={
        'html': '<blockquote class="instagram-media" data-instgrm-captioned data-instgrm-permalink="https://www.instagram.com/p/POST_ID/" data-instgrm-version="14"></blockquote><script async src="//www.instagram.com/embed.js"></script>',
        'css': 'body { margin: 0; padding: 16px; background: white; } .instagram-media { margin: 0 auto !important; min-width: 326px !important; max-width: 550px !important; width: calc(100% - 2px) !important; }',
        'width': 600, 'height': 800, 'ms_delay': 1500,
    },
)
url = response.json()['url']
```

## Common pitfalls

- **Embed widget never renders.** Instagram throttles automated traffic. The widget can fail entirely on a busy day. Prefer the [Instagram Square Post template](https://html2img.com/templates/instagram-square-post/) for reliability.
- **Post is from a private account.** The embed shows a placeholder. Confirm the account is public.
- **Image lazy-loads after capture.** Increase `ms_delay` to 3000ms if the image is missing from the output.

## See also

- [JavaScript integration guide](https://html2img.com/integrations/javascript/), [Python integration guide](https://html2img.com/integrations/python/)
- [css parameter](https://html2img.com/docs/parameters/css/), [ms_delay parameter](https://html2img.com/docs/parameters/ms_delay/)

<script type="application/ld+json" set:html={JSON.stringify({
  "@context": "https://schema.org",
  "@type": "HowTo",
  "name": "How to Capture an Instagram Embed as an Image",
  "description": "Render an Instagram post embed as a PNG using the HTML to Image HTML API.",
  "step": [
    { "@type": "HowToStep", "name": "Build the embed HTML", "text": "Wrap the Instagram post permalink in the official blockquote and include embed.js." },
    { "@type": "HowToStep", "name": "POST to the API", "text": "Send the HTML, CSS, width, height and ms_delay to the HTML to Image HTML endpoint." },
    { "@type": "HowToStep", "name": "Use the returned URL", "text": "Drop the i.html2img.com URL into your newsletter or page." }
  ]
})}></script>
