GitHub Pages Contact Form Without a Backend

You pushed your site to GitHub, switched on Pages, and it loaded at username.github.io/my-site/. Then you added a contact form, clicked Send, and the browser showed a 405 error or nothing at all.
That happens because GitHub Pages only serves files. It can show the page that holds your form, but it has no code running that could receive a submission. The fix is to let Pages serve the HTML and point the form at a hosted endpoint (a URL that accepts form data on your behalf). We use Formtorch for that in this guide.
This walkthrough uses a project site at username.github.io/my-site/, because that URL shape trips people up on the thank-you page. The same steps work for a user site at username.github.io, with fewer paths to worry about.
What you need before you start
You need a GitHub repository with an index.html at its root, a Formtorch account, and a form endpoint. If you do not have an endpoint yet, the HTML quickstart walks through creating the project and form, and the endpoint looks like https://formtorch.com/f/YOUR_FORM_ID.
For general background on why static hosts cannot process forms, and for a JavaScript version with loading states, read How to add a contact form to a static website without a backend. This post stays with GitHub Pages and the repo details.
Lay out the repository
A project site is a folder in your repository, so the layout decides your URLs. We will use two pages: the form at the root and a thank-you page in its own folder.
my-site/
index.html -> https://username.github.io/my-site/
thanks/
index.html -> https://username.github.io/my-site/thanks/Putting the thank-you page at thanks/index.html gives it a clean URL with a trailing slash, and it keeps the repository tidy as you add pages.
Add the form to index.html
Here is a complete index.html you can copy. It is a plain HTML form with no JavaScript, and it is built so keyboards, screen readers and browser autofill all work.
<!-- index.html -->
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Contact us</title>
</head>
<body>
<main>
<h1>Contact us</h1>
<form action="https://formtorch.com/f/YOUR_FORM_ID" method="POST">
<input
type="hidden"
name="_redirect"
value="https://username.github.io/my-site/thanks/"
/>
<p>
<label for="name">Name</label><br />
<input
id="name"
name="name"
type="text"
autocomplete="name"
required
/>
</p>
<p>
<label for="email">Email</label><br />
<input
id="email"
name="email"
type="email"
autocomplete="email"
required
/>
</p>
<p>
<label for="message">Message</label><br />
<textarea id="message" name="message" rows="5" required></textarea>
</p>
<button type="submit">Send message</button>
</form>
</main>
</body>
</html>Replace YOUR_FORM_ID with the ID from your endpoint URL, and replace username and my-site with your GitHub username and repository name.
A few of these choices are there for accessibility, not decoration:
<label for>matched to eachid: clicking a label focuses its field, and screen readers announce the label when the field gets focus.autocomplete="name"and"email": browsers can fill these fields for you, which helps anyone who finds typing slow or difficult.type="email": phones show an email keyboard, and the browser checks the format before it sends anything.nameon every field: Formtorch uses thenameto label each value in your dashboard, and a field without one is not sent.lang="en"and one<h1>: screen readers pick the right pronunciation, and the page has a clear starting point.
Labels sit above the inputs here so the markup stays short. Add your own CSS, or start from the basic HTML contact form template if you want styled markup to paste in.
Set the Pages publishing source
Pages needs to know which branch and folder to publish. In your repository, open Settings, choose Pages, and find the Build and deployment section. Under Source, pick Deploy from a branch, then choose your main branch and the /(root) folder and click Save.
If you keep your site in a docs/ folder instead, choose /docs in the folder dropdown. Then index.html and thanks/ live inside docs/, and the URLs stay the same.
GitHub also offers GitHub Actions as a source, which suits sites that need a build step such as Hugo or Eleventy. For hand-written HTML, deploying from a branch is the lower-effort option, and GitHub's own documentation recommends it when you do not need control over the build.
Your project site then appears at https://username.github.io/my-site/. Pages sites are public on the internet, even when the repository is private on plans that allow it, so keep anything sensitive out of the repo.
Build the thank-you URL with your repo path
This is the step where project sites differ from user sites. The hidden _redirect field tells Formtorch where to send the visitor after a successful submission, and the value needs the repo name in it.
<input
type="hidden"
name="_redirect"
value="https://username.github.io/my-site/thanks/"
/>The reason to write the full URL is that a shorter value can silently lose /my-site. A root-relative value such as /thanks/ resolves against the site root, so it points at username.github.io/thanks/, which is a 404. A path without a leading slash, such as thanks/, resolves against the page the browser reports as the referrer. Browsers often report only the origin on cross-site form posts, so that value can drop the repo name too. The full URL avoids both problems.
Formtorch also checks that a _redirect value stays on the same site as your form page, which protects your visitors from a tampered hidden field. https://username.github.io/my-site/thanks/ passes because it shares an origin with your form, and a URL on another domain does not. If the browser sends no referrer at all, Formtorch ignores _redirect and shows its default success page.
For a setting that does not depend on the browser's referrer, use the dashboard instead. Open your form, then Settings, then Success Redirect, turn on Redirect after submission, enter the same full URL and save. It accepts any https:// URL, and when it is on it overrides the hidden field.
Now create the thank-you page itself.
<!-- thanks/index.html -->
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Message sent</title>
</head>
<body>
<main>
<h1>Thanks, we got your message</h1>
<p>We will reply to the email address you gave us.</p>
<p><a href="../">Back to the contact page</a></p>
</main>
</body>
</html>The back link uses ../ rather than /, so it stays inside the repo path. The same rule applies to your CSS and images: on a project site, /style.css points at the account root, while style.css or ../style.css points into your project.
Push and test with dummy data
Commit both files and push to the branch you chose as the source. Pages then publishes the change, which can take a little while, so refresh the Pages settings screen until it shows your site as live.
Open https://username.github.io/my-site/ and send a test entry with clearly fake details, such as Test Person and test@example.com. Then check three things:
- The browser lands on
https://username.github.io/my-site/thanks/. - The entry appears under Submissions in your Formtorch dashboard.
- A notification email arrives in your inbox. New projects send notifications to your account email by default, and it is already verified.
While you build, you can add <input type="hidden" name="_test" value="true" /> to mark entries as tests. Test entries skip the email and do not count toward your quota, so remove that field before you check the inbox and before you go live.
Spam, privacy and the form ID
Your form ID sits in public HTML, so anyone can read it and post to it. Formtorch runs TorchWarden spam checks on every submission by default, and a honeypot field adds a hidden trap that bots tend to fill in. For more options, see How to prevent spam in contact forms.
On a paid plan you can also restrict which websites may submit. Add the hostname username.github.io under Allowed Domains in the form settings. Matching is by hostname only and ignores the path, so every project site under your username shares that entry. It limits your form to your own GitHub Pages sites, but it cannot tell one repo from another. Check pricing for which plans include it, and read the domain restriction docs for the Origin: null case that affects pages with a strict referrer policy.
If something does not work
- 405 or a blank page on submit: the form
actionstill points at your own site. It must be the fullhttps://formtorch.com/f/...URL. - The default Formtorch page appears instead of your thank-you page: the
_redirectvalue is on a different origin than the form page, or the browser sent no referrer. Use the exacthttps://username.github.io/...URL, or set the redirect in form settings. - A 404 after submitting: the thank-you URL is missing the repo name. Compare it with your project URL character by character.
- Nothing in the dashboard: check that every field has a
name, and that_testis not hiding the entry from your email. Spam-flagged entries are stored separately in the dashboard.
Where to go from here
GitHub Pages serves the form and Formtorch receives it, so the only things you maintain are two HTML files and one endpoint URL. When you want inline success messages instead of a redirect, the fetch version in the static website guide drops into the same index.html.
Add a contact form to your GitHub Pages site.
Create a free Formtorch account, copy your endpoint URL, and paste it into your form's action.
Related posts

How to Add a Contact Form to a Static Website Without a Backend (2026)

Why static sites still need a backend (just not the kind you think)

How to send an HTML form to Google Sheets (2 ways)
