Contact form for GitHub Pages
Add a working contact form to a GitHub Pages site
GitHub Pages only serves static files, so a form on it has nowhere to send its data. Point the form at Formpit and every submission is emailed to you and kept in an inbox, with no server and no build step.
How to set it up
- Create a free form in Formpit and copy its endpoint URL from the Setup tab.
- Paste the form below into any page of your repository (for example
contact.html) and replaceYOUR_FORM_ID. - Commit and push. Once GitHub Pages has rebuilt the site, send a test from the live page.
contact.html
<form action="https://formpit.com/f/YOUR_FORM_ID" method="POST">
<label>Name <input type="text" name="name" required></label>
<label>Email <input type="email" name="email" required></label>
<label>Message <textarea name="message" rows="5" required></textarea></label>
<input type="text" name="_gotcha" style="display:none" tabindex="-1" autocomplete="off">
<input type="hidden" name="_redirect" value="https://YOURNAME.github.io/thanks.html">
<button type="submit">Send</button>
</form>Replace YOUR_FORM_ID with the endpoint from your form's Setup tab.
Good to know
- The
_redirectfield sends people back to a thank-you page on your own site. Remove it to use Formpit's thank-you page instead. - Works the same on a custom domain, and with Jekyll, Hugo or plain HTML.
Why a GitHub Pages form needs a service
GitHub Pages serves the files in your repository exactly as they are. There's no PHP, no server code and no way to run a script when someone submits a form, so a form on its own has nowhere to send its data. A form backend fills that gap: the form posts to its URL, and it stores the submission and emails it to you.
Adding a thank-you page
Create thanks.html in your repository with a short message, then point the hidden _redirect field at its full URL. If you'd rather not maintain a page, remove the field: Formpit shows its own thank-you page, which you can style with your colours and logo.
Staying on the page with JavaScript
To show a message without leaving the page, send the form with fetch() and an Accept: application/json header, then swap the form for a thank-you note. GitHub Pages serves plain JavaScript files, so a small <script> tag at the bottom of the page is enough. See the guide to making an HTML form send email for the code.
Keeping spam out
The hidden _gotcha field catches most bots. Formpit also limits how often one address can submit and checks the content, and you can add hCaptcha, reCAPTCHA or Turnstile in the form's settings. Locking the form to your github.io domain in Formpit stops other sites from posting to it.
What you get
- Every submission emailed to you and stored forever in an inbox with New / Replied / Closed statuses.
- Reply from the inbox, add tags and notes, search, export CSV or JSON.
- Spam filtering with a honeypot, rate limiting and content checks; hCaptcha, reCAPTCHA or Turnstile if you want it.
- 500 submissions a month free. Pro adds file uploads, Google Sheets, Notion, Slack, webhooks and reminders.
Questions
Can GitHub Pages handle forms?
Not on its own, because it only serves static files. Point the form at a form backend such as Formpit, which receives the submission and emails it to you.
Is it free?
GitHub Pages is free, and Formpit's free plan covers 500 submissions a month on unlimited forms.
Do I need Jekyll for this?
No. The form is plain HTML and works on any GitHub Pages site. If you do use Jekyll, see the Jekyll guide for an include you can reuse.
Other platforms
Lovable · Bolt · v0 · WordPress · Shopify · Wix · Squarespace · Framer · Webflow · Carrd · Plain HTML · React · Next.js · Astro · Hugo & Eleventy · Vue & Nuxt · Svelte & SvelteKit · Jekyll