Formspree Logo
Guide Thumbnail
+

Adding a Form to Netlify

In this guide we’ll show you how to add a contact form to your Netlify website using Formspree.

Formspree is a form backend that works with any Netlify site. You point your form’s action at a Formspree endpoint, with no detection step or server code.

Netlify’s built-in Netlify Forms only works where Netlify’s build can read your HTML. It registers forms at deploy time, so it does not detect forms that JavaScript renders. It may also skip submissions when the form’s POST path is redirected or handled by a function. By the end of this guide, you’ll have a working form on your Netlify site that submits via Formspree and notifies you by email.

Prerequisites

To follow this guide, you’ll need:

  • A Formspree account (you can sign up for free here)
  • A Netlify site, or a project you’re ready to deploy to Netlify

Adding a Form to Netlify

On Netlify, a Formspree form is plain HTML in your site’s source, with its action set to a Formspree endpoint.

Step 1: Add the Form Code

Add this form to a page in your site:

<form action="https://formspree.io/f/YOUR_FORM_ID" method="POST">
  <input type="text" name="_gotcha" style="display:none" />
  <label>Email <input type="email" name="email" required></label>
  <label>Message <textarea name="message" required></textarea></label>
  <button type="submit">Send</button>
</form>

Each input needs a name attribute, and method must be POST.

Step 2: Create a Form Endpoint

In the Formspree dashboard, click + Add New in the top left and choose New Form. Name it, set Send emails to to the address that should receive submissions, and click Create Form.

The Formspree Create Form dialog with Form Name, Project, and Send emails to fields

Copy the endpoint from the form’s Integration tab:

The Integration tab of a Formspree form with the form endpoint URL and Copy button, marked by an arrow

Step 3: Set the Form action to the Formspree Form Endpoint

Replace the entire value of the form’s action attribute with the endpoint you copied. Reference: Building an HTML form.

Step 4: Deploy and Test Your Site

Deploy the site and submit the form. The submission appears in the form’s Submissions tab, and Formspree emails it to the form’s target email. This route needs no Netlify setting, detection, or build step.

Forms Rendered by JavaScript (React, Next.js, Astro Islands, SvelteKit)

Netlify Forms will not work with a JavaScript-rendered form. It only registers forms found in the built HTML, so it never sees one that JavaScript renders. The documented workaround is a hidden static copy of the form, covered below in the If You Use Netlify Forms section. Using Formspree instead is a much simpler alternative.

If JavaScript renders your form, post to the endpoint with fetch. There is no detection step, so no static copy of the form is needed:

const res = await fetch("https://formspree.io/f/YOUR_FORM_ID", {
  method: "POST",
  headers: { Accept: "application/json" },
  body: new FormData(form),
});
if (res.ok) {
  // show your success message
}

Framework walkthroughs: Next.js, Gatsby, Astro, Eleventy, and Jekyll.

Find Submissions

Open the form’s Submissions tab. Submissions go to Inbox or Spam, or to Over Limit past your monthly limit.

Send Notifications

Submissions are emailed to the form’s target email, and an input named email sets the Reply-To (docs). Workflow actions add Slack, webhooks, and an Auto Response email to the submitter (Professional and Business).

Block Spam

The _gotcha honeypot in Step 1 makes Formspree silently ignore any submission where it has a value (honeypot). CAPTCHA is in the form’s Settings tab under Spam protection (reCAPTCHA settings).

Deploy Previews and Branch Deploys

A preview posts to the action in its HTML, which is your production form unless you change it. Two options:

  1. One form per deploy context. Create a second Formspree form and set the endpoint per context in netlify.toml:

    [build.environment]
      FORM_URL = "https://formspree.io/f/PROD_FORM_ID"
    
    [context.deploy-preview.environment]
      FORM_URL = "https://formspree.io/f/TEST_FORM_ID"
    
    [context.branch-deploy.environment]
      FORM_URL = "https://formspree.io/f/TEST_FORM_ID"
    

    In a framework, keep your existing build command and read the variable through the framework’s environment variables. Browser code needs a public prefix such as NEXT_PUBLIC_, PUBLIC_, or GATSBY_ (see the Astro and Gatsby guides).

    On a plain HTML site, use a placeholder in the form and fill it in at build time. Replace index.html with the page that holds the form:

    <form action="FORM_URL" method="POST">
    
    [build]
      command = "sed -i \"s|FORM_URL|$FORM_URL|g\" index.html"
    

    If FORM_URL is unset for a context, action ends up blank.

  2. Restrict the production form to your domain. In your project’s Settings tab, enter your production domain under Restrict to Domain, without a protocol or www. Submissions from other domains, including netlify.app previews, go to the spam inbox (Restrict to Domain).

Set Up a Thank-You Page

Set the redirect in the form’s Settings tab on Personal, Professional, or Business, using the page’s full URL (Thank You redirect). Without one, Formspree shows its own Thank You page.

Netlify serves your thank-you page, so your _redirects rules apply to it. A rule does not override a URL that exists as a file, unless the rule ends in !:

# Single-page app fallback. /thank-you/index.html still renders.
/*  /index.html  200

# The ! forces the rewrite and breaks the thank-you page.
/*  /index.html  200!

If You Use Netlify Forms

After each build, Netlify parses the static HTML files in the deploy. For each <form> with data-netlify="true" or netlify, it registers the form under its name, strips the attribute from the deployed markup, and injects a hidden input:

<input type="hidden" name="form-name" value="contact" />

A submission is a POST to a path on your own site, and form-name identifies the registered form. That has three consequences:

  • JavaScript-rendered forms are not detected. They are not in the built HTML. Add a hidden static copy with the same name and an input for every field, and send form-name in a URL-encoded body, because Netlify Forms does not accept JSON:

    <!-- public/__forms.html -->
    <form name="contact" data-netlify="true" hidden>
      <input name="email" />
      <textarea name="message"></textarea>
    </form>
    
  • Enabling detection is not retroactive. After you select Enable form detection under Forms, redeploy.

  • Redirects can block a submission. Netlify may skip a submission when the form’s POST path is redirected or handled by a function, so post to a static route (troubleshooting FAQ).

If a form is missing from the Forms tab, check that the <form> has data-netlify="true" or netlify and a unique name, and that it is in the built HTML. Akismet flags test data such as test@test.com as spam, so also check Spam submissions (troubleshooting tips).

Use Netlify Forms only for the simple case: a static HTML form whose submissions you only need emailed to you. It is free and unlimited on credit-based plans, and metered on legacy plans (usage and billing).

For every other use case, use Formspree.


Got Feedback?