# Embedding

> Put a form on your own website inline, as a popup, as a slider from the side, or filling the whole window.

Any published form can live on your own website. Open the form, choose **Share**, then the **Embed** tab, pick how it should appear, and copy the snippet into your page's HTML.

## Four ways to show a form

| Option          | What it looks like                                      |
| --------------- | ------------------------------------------------------- |
| **In the page** | Sits in your page wherever you paste it, like an image. |
| **Popup**       | A button that opens the form over your page.            |
| **Slider**      | A button that slides the form in from the side.         |
| **Full page**   | Fills the whole window, for a page of its own.          |

A snippet for **In the page** looks like this:

```html
<div data-formhelix="FORM_ID"></div>
<script src="https://formhelix.com/embed.js" async></script>
```

And a popup:

```html
<button type="button" data-formhelix="FORM_ID" data-formhelix-mode="popup">Open form</button>
<script src="https://formhelix.com/embed.js" async></script>
```

You only need the `<script>` line once per page, however many forms the page has. The button can be any button or link of your own: what matters is the `data-formhelix` attributes on it.

## Options

Add these attributes to the same element:

| Attribute                                      | What it does                                                                                                      |
| ---------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| `data-formhelix-mode`                          | `popup`, `slider` or `fullpage`. Leave it out for in the page.                                                    |
| `data-formhelix-height="560"`                  | In the page: the frame's height in pixels. The form scrolls inside it when a step, or a one-page form, is taller. |
| `data-formhelix-side="left"`                   | A slider's side. Right by default.                                                                                |
| `data-formhelix-hidden="source=site&plan=pro"` | Values for the form's [hidden fields](https://formhelix.com/docs/hidden-fields).                                                       |
| `data-formhelix-forward-query`                 | Also pass this page's own query string, so a page opened as `?source=ads` fills in the `source` hidden field.     |
| `data-formhelix-auto-close="2000"`             | Close a popup or slider this many milliseconds after the form is finished.                                        |
| `data-formhelix-title="Signup form"`           | The frame's name for screen readers.                                                                              |

## Sites that don't allow scripts

Some website builders only accept an `<iframe>`. Tick **Plain iframe, for sites that don't allow scripts** in the **In the page** option to get one. A plain iframe can't open as a popup or slider, and a redirecting ending only moves the frame, not the whole page.

## Reacting when a form is finished

The element with `data-formhelix` fires a `formhelix:complete` event when the respondent finishes. It bubbles, so you can listen anywhere on the page:

```html
<script>
  document.addEventListener("formhelix:complete", () => {
    // Show your own message, start a download, record a conversion…
  });
</script>
```

## Opening a form from your own code

`embed.js` adds a small `formhelix` object to the page:

| Call                                           | What it does                                                                   |
| ---------------------------------------------- | ------------------------------------------------------------------------------ |
| `formhelix.open("FORM_ID", { mode: "popup" })` | Open a popup (or `slider`) without a button.                                   |
| `formhelix.close()`                            | Close the open popup or slider.                                                |
| `formhelix.load()`                             | Look for new `data-formhelix` elements, for pages that add them after loading. |

Pressing <kbd>Escape</kbd> in a popup or slider closes it.

## How embedded forms behave

- **Endings that redirect** move your whole page to the ending's link, not just the frame.
- **Saving progress** works as usual. In browsers that block cookies inside frames from other sites (such as Safari), progress is kept for as long as the page stays open, so reloading the page starts the form again.
- **Password-protected forms** ask for the password inside the frame.
- The form keeps its own [design](https://formhelix.com/docs/design). Match it to your site in the form's **Design** settings.
