# Popup Form Embed



<Warning>
  **WAIT...** Make sure that you have added the [**Surface Tag**](/docs/surface-tag/installation) to your site before proceeding.
</Warning>

## Edit Head Tag [#edit-head-tag]

Add the following code snippet to your site's `head` tag to enable the popup form.

```html
<!-- Start Surface Form Embed -->

<script>
  (function () {
    const surface_src = "REPLACE ME WITH FORM URL"
    const surface_embed_type = "popup"
    const target_element_class = "surface-form-button"
    const c = new SurfaceEmbed(surface_src, surface_embed_type, target_element_class)
  })();
</script>

<!-- End of Surface Form Embed -->
```

Replace the &#x2A;*`REPLACE ME WITH FORM URL`** with the url to your surface form found by clicking the share button on the surface platform.

## Choose trigger buttons [#choose-trigger-buttons]

The next step is to choose which buttons you'd like to trigger the form. This is done by simply adding the class name `surface-form-button` to the elements which should be able to make the form appear.

```html
<button class="... surface-form-button"> </button>
```

## Control Popup Size [#control-popup-size]

You can control the size of the popup that appears on your site. See the following snippet:

```html
<!-- Start Surface Form Embed -->

<script>
  (function () {
    const surface_src = "REPLACE ME WITH FORM URL";
    const surface_embed_type = "popup";
    const target_element_class = "surface-form-button";
    const c = new SurfaceEmbed(surface_src, surface_embed_type, target_element_class);

    c.popupSize = "medium"; // This value can be "small", "medium", or "large"
  })();
</script>

<!-- End of Surface Form Embed -->
```

## Direct Link [#direct-link]

Append `showSurfaceForm=true` to the url of your website.

For example:

```
https://YOUR_WEBSITE.com/?showSurfaceForm=true
```

<Info>
  Replace `YOUR_WEBSITE.com` with your actual website URL.
</Info>

This will automatically trigger the popup form to appear when the page loads, without requiring the user to click a trigger button.

## Optimize Speed [#optimize-speed]

Add the following `<link>` tags inside the `<head>` of your site:

```html
<!-- Speed up connections to forms.withsurface.com by performing early DNS resolution and TCP handshake -->
<link rel="dns-prefetch" href="https://forms.withsurface.com">
<link rel="preconnect" href="https://forms.withsurface.com" crossorigin>

<!--  Fetch the form in advance, so it's ready when a user opens it. -->
<link rel="prefetch" href="REPLACE ME WITH FORM URL" as="document">
```

<Info>
  Replace `REPLACE ME WITH FORM URL` with a Surface Form URL.
</Info>

### Explanation [#explanation]

1. dns-prefetch → Resolves the domain early to skip DNS lookup delays.
2. preconnect → Prepares the TCP + TLS handshake so the browser is ready to request assets immediately.
3. prefetch → Fetches the form in advance, so it's ready when a user opens it.
