Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 11 min read

Contact form for a static website that works without JS

You have a static site: a few HTML files on GitHub Pages, Netlify, Cloudflare Pages or an S3 bucket, maybe built with Hugo, Jekyll or Astro. There's no server of your own behind it, and now it needs a contact form. Searc

Contact form for a static website that works without JS

You have a static site: a few HTML files on GitHub Pages, Netlify, Cloudflare Pages or an S3 bucket, maybe built with Hugo, Jekyll or Astro. There's no server of your own behind it, and now it needs a contact form. Search for how to add one and the advice is nearly always the same: sign up with a form service and paste its snippet, with your key in a hidden field. You send yourself one test message, it lands in your inbox, and you move on.

That test ran on your laptop, over a fast connection, with JavaScript working, and you pressed Send once. Your visitors don't always get that. So on 26 November 2026 we took the snippets that the pages ranking for this question hand out (Web3Forms, Formspree, Static Forms and Formgrid) and ran them in Chromium 153, Firefox 155 and WebKit 26.6 with Playwright 1.63.0. We didn't check whether the email arrives, because that needs an account with each service. We checked what a visitor sees when the script is off or late, when they click twice, when the server fails or never answers, and whether a screen reader hears the result.

The short answer

A static host only hands out files, so a contact form on a static website has to send its POST somewhere else: a hosted form backend, or a serverless function you write yourself. Start from the plain HTML version of the snippet, a <form> with a real action and method="POST", because it's the only version that still sends when JavaScript is off or slow to load. Put a script on top for the inline "Thanks" message, and make that script ignore a second click, keep the visitor's text when sending fails, give up after a timeout, and write its messages into a role="status" element that is already on the page. The form near the end of this post does all of that.

What the top results tell you

We could read seven of the eight pages Google showed for "contact form for static website" (Reddit blocks our tools). Four belong to form services, each with a snippet that posts to its own endpoint. A 2017 Medium post walks through mailto, an Express server, AWS Lambda and an integration platform, and the Cloudflare forum thread and the Stack Overflow question mostly name services. None of them tests anything, or says what the form does with JavaScript off, on a double click, or when the server is down.

So we put each snippet, byte for byte, on a local page served the way a static host serves it: GET works, and a POST gets 405, the answer GitHub Pages, Vercel and Cloudflare gave in our static host test. Playwright's router answered the requests meant for each service, so nothing reached them, and we could make that "server" slow, broken or silent on purpose.

With JavaScript off, the JavaScript versions don't send

Three of the snippets are plain HTML: the main Web3Forms example, Static Forms and Formgrid. Each is a <form> with the service's URL in action and method="POST", and with JavaScript switched off all three did what they should: one POST to the service in every browser.

The other two depend on a script. Web3Forms' JavaScript tab starts with <form method="POST" id="form"> and no action, so without the script the browser posts the form back to its own page, and the static host answers with an error ("405 Not Allowed" on GitHub Pages). Formspree's script-tag example for @formspree/ajax is just <form id="my-form">, with no action and no method. A form with no method sends a GET: the page reloads with empty fields, nothing goes to Formspree, and the address bar reads:

/formspree-ajax.html?email=ann%40example.com&message=Hi%2C+do+you+ship+to+Canada%3F+%28test+2026-11-26%29

In all three browsers the visitor's email and message ended up in the URL, which means their browser history and your host's access log.

A slow CDN does the same with JavaScript on

Few people turn JavaScript off, but a script that hasn't arrived yet is common. The Formspree example loads its library from unpkg with defer, so the form is usable before the library is. We held unpkg's answer back for 4 seconds, as a bad mobile connection might. Our test filled in the form and pressed Send 0.3 to 0.4 seconds after the page started loading, and that press did the same GET as above: the message went into the URL and nothing was sent. With no delay, the same click sent one POST to Formspree. A real action and method="POST" on the form would turn that early press into an ordinary post to the service.

The Web3Forms script clears the form even when sending fails

The JavaScript example ends like this:

.catch(error => {
    console.log(error);
    result.innerHTML = "Something went wrong!";
})
.then(function() {
    form.reset();
    setTimeout(() => {
        result.style.display = "none";
    }, 3000);
});

The last .then() runs after the .catch() too, so the form is reset whether the message went through or not. With the network cut, the page said "Something went wrong!" and the visitor's text was gone. A 400 from the server also left an empty form.

Three seconds later the result box gets display: none, and nothing sets it back, so a second message in the same visit gets its "Form submitted successfully" written into an invisible box. When the server didn't answer at all, "Please wait..." stayed up for the 17 seconds we waited, the button stayed active, and a second press sent a second request.

Formspree's library handles more of this: a double click sent one request, and after an error the text stayed in the form. But with a silent server the button stayed disabled and no message appeared in 17 seconds, and a network failure showed the browser's raw error text: "Failed to fetch" in Chromium, "NetworkError when attempting to fetch resource." in Firefox, "Load failed" in WebKit.

Two clicks on a plain HTML form send two messages

A plain form has no script to stop a second click. We made the "service" take 2 seconds to answer, like a serverless function waking up, and clicked twice. A fast double click sent one POST in Chromium and WebKit and two in Firefox, 31 to 84 milliseconds apart. Two clicks half a second apart sent two in 23 of our 24 runs across the three browsers (one WebKit run sent one), and both reached the server.

Without JavaScript the page can't prevent that, so the copy has to be caught on the server. In Formgong you can switch on a filter (Settings β†’ Protection) that sends the same text to the same form within 24 hours to the Spam tab instead of your inbox. With other services, check their docs or expect the odd duplicate.

Will a screen reader hear "Thanks"?

Screen readers announce new text when it appears inside a live region, an element with role="status", role="alert" or aria-live. MDN's guide to live regions sets one condition: "Establish the live region before updating its content." Neither JavaScript example has a live region. Web3Forms writes into a plain div, and the @formspree/ajax 1.1.5 package sets aria-busy and aria-invalid but has no aria-live or role anywhere in it.

We read Chromium's accessibility tree, which is what it hands to a screen reader, through the DevTools protocol after each message appeared. In both examples the text sat in a generic container with no live property, so a screen reader has nothing to announce. Formspree's library also disables the button while it sends, and in all three browsers that dropped keyboard focus back to the page, so the next Tab starts from the top.

The results side by side

What we did Plain HTML snippets (3) Web3Forms, JavaScript tab Formspree, @formspree/ajax Our form
Send with JavaScript off 1 POST to the service 405 from your host GET, text in the URL 1 POST to the service
Send before a 4 s late library n/a n/a GET, text in the URL n/a
Double click, server takes 2 s 1 POST (2 in Firefox) 2 POSTs 1 POST 1 POST
Server answers 400 n/a Text erased Text kept Text kept, server's message shown
Network cut n/a Text erased Text kept, raw browser error Text kept, plain message
No answer for 17 s n/a "Please wait...", a 2nd press sends again Button stuck, no message Note at 15 s, button works
Message in a live region n/a No No Yes

"n/a" means the case doesn't apply: the plain forms load no library and leave the page when they send, and the other two scripts are inline.

A contact form you can paste into a static site

This is the form we ended up with. Paste it where the form should go and change the key and the thank-you address.

<form id="contact" action="https://formgong.com/submit" method="POST">
  <input type="hidden" name="access_key" value="YOUR_FORM_KEY">
  <input type="hidden" name="redirect" value="https://your-site.example/thanks/">

  <label>Name <input name="name" autocomplete="name" required></label>
  <label>Email <input name="email" type="email" autocomplete="email" required></label>
  <label>Message <textarea name="message" rows="5" required></textarea></label>

  <div class="trap" aria-hidden="true">
    <label>Leave this empty <input name="botcheck" tabindex="-1" autocomplete="off"></label>
  </div>

  <button type="submit">Send message</button>
  <p class="status" role="status" aria-live="polite"></p>
</form>

<style>
  #contact { display: grid; gap: 14px; max-width: 30rem; font: 16px/1.5 system-ui, sans-serif; color: #1c2230; }
  #contact label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; }
  #contact :is(input, textarea) { font: inherit; font-weight: 400; padding: 10px 12px; border: 1px solid #d0d5dd; border-radius: 8px; }
  #contact :is(input, textarea):focus { outline: 2px solid #4f46e5; outline-offset: 1px; }
  #contact button { justify-self: start; font: inherit; font-weight: 600; padding: 10px 22px; border: 0; border-radius: 8px; background: #4f46e5; color: #fff; cursor: pointer; }
  #contact button[aria-disabled="true"] { opacity: .6; cursor: progress; }
  #contact .status { margin: 0; border-radius: 8px; }
  #contact .status:not(:empty) { padding: 10px 12px; background: #eef0ff; }
  #contact .status[data-kind="error"] { background: #fdecec; color: #8a1c1c; }
  #contact .trap { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
</style>

<script type="module">
  const form = document.querySelector("#contact");
  const button = form.querySelector("button");
  const status = form.querySelector(".status");
  let sending = false;

  function show(text, kind) {
    status.dataset.kind = kind;
    status.textContent = text;
  }

  form.addEventListener("submit", async (event) => {
    event.preventDefault();
    if (sending) return; // a second click or Enter while the first request runs
    sending = true;
    button.setAttribute("aria-disabled", "true");
    show("Sending…", "info");
    try {
      const res = await fetch(form.action, {
        method: "POST",
        headers: { Accept: "application/json" },
        body: new FormData(form),
        signal: AbortSignal.timeout(15000),
      });
      const data = await res.json().catch(() => ({}));
      if (res.ok && data.success) {
        form.reset();
        show("Thanks! Your message was sent.", "ok");
      } else {
        show(data.message || `Not sent (error ${res.status}). Please try again.`, "error");
      }
    } catch (err) {
      show(err.name === "TimeoutError" || err.name === "AbortError"
        ? "The server didn't answer in time. Your message may still have arrived, so wait a minute before sending it again."
        : "Couldn't reach the server. Your text is still here, so try again in a moment.", "error");
    } finally {
      sending = false;
      button.removeAttribute("aria-disabled");
    }
  });
</script>

The form in Chromium after our test server refused a message: the error sits under the button and the typed text is still in the fields

With JavaScript off it's an ordinary form: the service gets the POST and sends the visitor to the page in the redirect field. When the script runs, it takes over the same form and asks for JSON.

A sending flag makes a second submit do nothing while the first one runs. The button gets aria-disabled rather than disabled, which would drop keyboard focus. The form is reset only after the server says the message was stored, and after 15 seconds without an answer the script stops waiting and says the message may still have arrived, since a request that timed out on the page can still reach the server.

The status line is a <p role="status" aria-live="polite"> that's in the page from the start (MDN suggests the extra aria-live for older screen readers). It isn't hidden with display: none while empty, because a hidden element drops out of the accessibility tree; the empty line just has no padding. The honeypot sits 9,999 pixels off-screen with aria-hidden and tabindex="-1", so people, keyboards and screen readers skip it, and a bot that fills every field fills it too.

It posts to Formgong, the form backend we make, because that's the endpoint we could test end to end. The key comes from the Formgong page for plain HTML sites, and the same site has free website templates with a contact form already wired in. For another service, change the action, the key field and the data.success check.

Our form Chromium 153 Firefox 155 WebKit 26.6
JavaScript off 1 POST 1 POST 1 POST
Double click, or Enter then a click 1 POST 1 POST 1 POST
400, network cut, no answer Text kept, message shown Same Same
Live region before Send Yes ("polite" in the tree) Yes Yes
Honeypot reachable by Tab or in the tree No No No
Focus after Send On the button On the button On the button
Live formgong.com, placeholder key "That access key does not exist.", text kept Same Same

What we couldn't test

We didn't sign up for any of the services, so we never saw their real success answers or checked that their emails arrive; our router played their endpoints with answers we wrote. We read the accessibility tree instead of running NVDA, JAWS or VoiceOver, so "nothing to announce" is the tree's prediction, not a recording. WebKit on Linux is Safari's engine but not Safari, we ran no phones, and the honeypot never met a real spam bot. With JavaScript off, our own form still sends two messages for two clicks half a second apart, and for a fast double click in Firefox. And the Reddit thread stayed closed to us.

If you use a screen reader every day, you can tell us more than the tree did. Put the form on a test page, press Send with NVDA, VoiceOver or TalkBack running, and write in the comments what it said. Trying it with Formgong and hitting a wall? We'd like to hear about that as well.

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.