# embed

## Table of Contents

- [Options](#options)
- [Examples](#examples)

---

oEmbed-style iframe HTML for rich cards. It resolves to an object with `html`, the markup to render, and `scripts`, the script tags the markup depends on:

```js
const{html,scripts}=awaitmicrolink.embed(

'https://www.youtube.com/watch?v=9P6rdqiybaw'

)
```

Any URL implementing the [oEmbed](https://oembed.com/) specification is supported — hundreds of providers, from YouTube and X to Spotify and TikTok. See the [iframe parameter](https://microlink.io/docs/api/parameters/iframe) for the list. It resolves to `null` when the provider doesn't expose an embed.

## Options

- `maxWidth` `<number>` — the maximum width of the embedded resource, in pixels.
- `maxHeight` `<number>` — the maximum height of the embedded resource, in pixels.

Both are forwarded per the oEmbed spec, so support depends on each provider. Any [shared option](https://microlink.io/docs/sdk/getting-started/options) applies too.

## Examples

Constrain the player to the column it renders in:

```js
const{html}=awaitmicrolink.embed(

'https://www.youtube.com/watch?v=9P6rdqiybaw',

{

maxWidth:350

}

)
```

Render a post whose widget needs a script, injecting both:

```js
const{html,scripts}=awaitmicrolink.embed(

'https://x.com/microlinkhq/status/1032664633960800257'

)

document.querySelector('#post').innerHTML=html

for(const{src,async}ofscripts){

constscript=document.createElement('script')

script.src=src

script.async=async

document.body.append(script)

}
```

For a static card instead of the provider's player, use [metadata](https://microlink.io/docs/sdk/methods/metadata) and render the fields yourself. For a drop-in component that does either, see [link preview](https://microlink.io/link-preview).

See the [embed guide](https://microlink.io/docs/guides/embed) for iframe versus card decisions, caching, and private pages.