> ## Documentation Index
> Fetch the complete documentation index at: https://docs.x.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Embedded Post JavaScript Factory Function

> Dynamically insert embedded X Posts into a webpage using the twttr.widgets.createTweet JavaScript factory function from the X for Websites library.

The X for Websites JavaScript library supports dynamic insertion of embedded Posts using the `twttr.widgets.createTweet` function. Pass a Post ID, target parent element, and any custom options.

The code snippets on this page assume `widgets.js` has successfully loaded on your page. Include an asynchronous script loader on your page while initializing `window.twttr` as described in our [JavaScript loader documentation](/x-for-websites/javascript-api/guides/set-up-x-for-websites). All JavaScript code depending on `widgets.js` should execute on or after `twttr.ready`.

| Parameter  | Description                                                                                                                                                     | Example value                          |
| ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------- |
| `tweetID`  | The numerical ID of the desired Post.                                                                                                                           | `'20'`                                 |
| `targetEl` | DOM node of the desired parent element.                                                                                                                         | `document.getElementById('container')` |
| `options`  | Override default widget options. See [Embedded Post parameter reference](/x-for-websites/embedded-posts/guides/embedded-tweet-parameter-reference) for details. | `{ theme: 'dark' }`                    |

## Example

An element with a DOM ID of `container` exists on the page.

```html theme={null}
<div id="container"></div>
```

The code snippet below will insert [Post ID 20](https://x.com/jack/status/20) into a page inside an element with a unique ID of `container`. The options object specifies a dark theme customization.

```javascript theme={null}
twttr.widgets.createTweet(
  '20',
  document.getElementById('container'),
  {
    theme: 'dark'
  }
);
```

## Promises

The `twttr.widgets.createTweet` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). You can execute code after a widget has been inserted onto your page by passing a callback to the resulting promise’s `then` function.

```javascript theme={null}
twttr.widgets.createTweet(...)
.then( function( el ) {
  console.log('Post added.');
});
```
