---
title: "ms_delay parameter"
description: "Wait a fixed number of milliseconds before capture, for iframes and lazy-loaded content."
url: "https://html2img.com/docs/parameters/ms_delay/"
---

# MS Delay Parameter

The `ms_delay` parameter adds a delay (in milliseconds) before capturing the screenshot, allowing time for animations, dynamic content, or resources to load.

## Specifications

| Property | Value |
|----------|-------|
| Type | integer |
| Required | No |
| Default | null |
| Range | 1-5000 (a value of `0` fails validation - omit the parameter for no delay) |
| API | Both HTML/CSS and Screenshot APIs |

## Description

The MS Delay parameter:
- Adds a specified delay before capturing the screenshot
- Useful for waiting for animations to complete
- Helps ensure dynamic content is fully loaded
- Can be used to capture specific states of interactive elements

> **Warning**
>
> Adding a delay increases the total processing time of your request. Only use delays when necessary, and keep them as short as possible for your use case.

## Examples

### Waiting for Animation
```json
{
    "html": "<div class='animate-fade-in'>Content with animation</div>",
    "ms_delay": 1000
}
```

### Capturing Slow Loading Sites
```json
{
    "url": "https://example.com/slow-page",
    "ms_delay": 2000
}
```

### Minimal Delay
```json
{
    "html": "<div>Simple content with short delay</div>",
    "ms_delay": 100
}
```

## Common values

- **500** - typical iframe with a single async asset.
- **1000** - Twitter or Instagram embed waiting for its widget script.
- **2000** - slow third-party widget that fetches data on mount.
- **5000** - avoid. If you need 5 seconds, your render is probably exceeding the budget. Use [wait_for_selector](https://html2img.com/docs/parameters/wait_for_selector/) instead.

## When to use

Use `ms_delay` when the content depends on an embed that does not expose a stable selector to wait for. Twitter and Instagram embed widgets are the canonical case. For your own markup, prefer [wait_for_selector](https://html2img.com/docs/parameters/wait_for_selector/) since it returns as soon as the element exists.

## Common mistakes

- **Stacking `ms_delay` and a long render budget.** A 4000ms delay plus a 25-second JavaScript render leaves only one second of margin. Trim the delay or move to `webhook_url`.
- **Using delay when a selector exists.** If you control the page, expose a marker like `<body data-ready="true">` and use `wait_for_selector="body[data-ready='true']"` instead.

See also: [twitter-embed example](https://html2img.com/docs/examples/twitter-embed/), [facebook-post example](https://html2img.com/docs/examples/facebook-post/), [instagram-post example](https://html2img.com/docs/examples/instagram-post/), [getting started guide](https://html2img.com/docs/getting-started/).

## Templates that use this parameter

Templates rendering complex external content lean on `ms_delay` to let scripts settle before capture:

- [Code screenshot template](https://html2img.com/templates/code-screenshot/)
- [GitHub social preview template](https://html2img.com/templates/github-social-preview/)
- [Tweet mockup card template](https://html2img.com/templates/tweet-mockup-card/)
