Guides

How to create a working contact form with HTML

Learn how to create a contact form and collect form submissions from your HTML form in 4 steps and under 3 minutes + Free form templates

How to create a contact form with formcarry in 4 steps
On this page8 sections
  1. After you read this guide
  2. Step 1: Create your HTML Form and CSS
  3. Step 2: Structure your form data
  4. Step 3: Point your form to backend
  5. Step 3.1: Create a form in formcarry
  6. Step 3.2: Integrate your form with formcarry
  7. Step 4: Collect submissions
  8. Conclusion

Contact forms are one of the best ways to convert more leads, and get the information you need from your visitors in a specific order, but usually it's not so easy to craft, in this guide we are going to make it easy like a cake!

Sometimes you may want to create a contact form without PHP, if that's the case, this tutorial might be really helpful to you.

After you read this guide#

  • You can create a working HTML contact form in 4 steps, under 3 minutes for free
  • You'll have a predefined CSS for you to quickly start
  • You can get email notifications from your contact form
  • You can export your contact form submissions as CSV and JSON
  • You don't have to deal with any back end code stuff (Php, Go, Node.js etc.)

Step 1: Create your HTML Form and CSS#

First, you'll need an HTML form in your web page, which is not a big deal, a basic HTML contact form will look like this.

HTML
1<form class="formcarryForm" action="#" method="POST">
2  <label for="firstNameInput">First Name</label>
3  <input type="text" id="firstNameInput" />
4
5  <label for="lastNameInput">Last Name</label>
6  <input type="text" id="lastNameInput" />
7
8  <label for="emailInput">Email</label>
9  <input type="email" id="emailInput" />
10
11  <label for="messageInput">Message</label>
12  <textarea id="messageInput" cols="30" rows="10"></textarea>
13
14  <button type="submit">Submit</button>
15</form>

A basic form in HTML is just a static thing that's only obligated to deliver the user input to a back-end script. You have to point the form to some script to actually process the data.

I have created a sample design for the sake of our blog post, which you can use it in your website for free.

HTML Contact Form example

Here's the CSS code that you can copy and use:

HTML
1<style>
2    @import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap");
3
4    /* 
5    CONTACT FORM EXAMPLE FOR formcarry
6
7    IMPORTANT NOTE:
8    PLEASE ADD formcarryForm class to your form element
9    to apply the styles.
10    */
11
12    * {
13        box-sizing: border-box;
14
15        /* colors */
16        --color-blue: #2552d0;
17        --color-light-blue: #3266e3;
18        --color-gray: #e5e7eb;
19        --color-dark-gray: #9da3ae;
20        --color-pink: #edadd2;
21
22        /* container */
23        --c-width: 50%;
24        --c-max-width: 500px;
25    }
26
27    body {
28        font-family: "Inter", sans-serif;
29    }
30
31    .formcarryContainer {
32        width: var(--c-width);
33        max-width: var(--c-max-width);
34        display: block;
35        margin: 10vh auto 0 auto;
36    }
37
38    .formcarryForm label {
39        display: block;
40        padding: 12px 0 2px 0;
41        letter-spacing: -0.2px;
42        cursor: pointer;
43        font-size: 16px;
44        font-weight: 700;
45    }
46
47    .formcarryForm input,
48    .formcarryForm textarea {
49        font-size: 16px;
50        display: block;
51        width: 100%;
52        padding: 10px;
53        background-color: var(--color-gray);
54        border: none;
55        border: 4px solid var(--color-gray);
56        outline: none;
57        border-radius: 8px;
58        color: var(--color-dark-gray);
59    }
60
61    .formcarryForm input:focus,
62    .formcarryForm textarea:focus {
63        background-color: #fff;
64        color: var(--color-dark-gray);
65    }
66
67    .formcarryForm input:focus:required:invalid {
68        border-color: var(--color-pink);
69        background-color: #fff;
70    }
71
72    .formcarryForm button {
73        display: block;
74        margin-top: 12px;
75        width: 100%;
76        padding: 12px 20px;
77        border-radius: 8px;
78        background-color: var(--color-blue);
79        color: #fff;
80        font-weight: 700;
81        font-size: 18px;
82
83        transition: 300ms all;
84    }
85
86    .formcarryForm button:hover {
87        background-color: var(--color-light-blue);
88    }
89
90    .formcarry-alert {
91        padding: 12px;
92        border-radius: 10px;
93        color: #fff;
94        font-size: 14px;
95        font-weight: 400;
96        margin-top: 12px;
97        display: none;
98    }
99
100    .formcarry-alert.visible {
101        display: block;
102    }
103
104    .formcarry-alert.success {
105        background: #69cf9d;
106    }
107
108    .formcarry-alert.error {
109        background: #de524c;
110    }
111</style>

Here's the live CodeSandbox demo

Update 6 Jan, 2022:

We have built free form generator tool that you can customize and get HTML code, make sure you check it out if you need form template.

Step 2: Structure your form data#

In order to send your form data to a script you need to name each of your fields so the script can match the values with the names (or the key).

You can add as many fields as you want.

Let's uniquely name each of our fields using name attribution.

HTML
1<form class="formcarryForm" action="#" method="POST">
2  <label for="firstNameInput">First Name</label>
3  <input type="text" id="firstNameInput" name="firstName" />
4
5  <label for="lastNameInput">Last Name</label>
6  <input type="text" id="lastNameInput" name="lastName" />
7
8  <label for="emailInput">Email</label>
9  <input type="email" id="emailInput" name="email" />
10
11  <label for="messageInput">Message</label>
12  <textarea id="messageInput" cols="30" rows="10" name="message"></textarea>
13
14  <button type="submit">Submit</button>
15</form>

Now we have a contact form that's ready to deliver the data to a script.

Step 3: Point your form to backend#

There's two ways to handle this step, this part is the most time consuming stuff due to you have to check fields, implement spam protection, create a mail server and make sure that it's working.

You can code your form backend on your own, or you can use formcarry (form backend) to process your form for free, that way you can get notification emails, use best in class spam protection and connect your submission data with other apps using Zapier.

If you want to code your own back-end take a look at How to create a contact form backend on your own.

Step 3.1: Create a form in formcarry#

Sign Up to formcarry for free, then click Add New to get your unique form backend URL

Creating a form in formcarry dashboard

Then copy your unique form endpoint

Step 3.2: Integrate your form with formcarry#

Copy your endpoint and paste it into action part of your form

Diff
- <form class="formcarryForm" action="#" method="POST">
+ <form class="formcarryForm" action="https://formcarry.com/s/{Your-Unique-Endpoint}" method="POST">

Step 4: Collect submissions#

We have crafted our form under few minutes and now you are ready to collect submissions, let's try our form!

Easy peasy 🙂, now refresh your formcarry dashboard to see the submission;

That's how easy it is, you can filter, sort and export your submissions from your formcarry dashboard.

You'll also get an email to the email addresses you have specified when you are creating the form;

Email notification for the new contact form submission, opened in an inbox

Conclusion#

I hope this blog post helped you! feel free to ask down there if anything didn't go expected.

It's really time consuming thing to create your own form backend but formcarry offers you the best solution, here's other things that you can benefit from using formcarry:

At formcarry all of our job is to make sure that your form endpoint is always online, provide you the best spam protection and allow you to always receive email notifications whenever you got a new submission!

If you haven't registered yet, Register formcarry for Free Now!

Nusu AlabugaFounder, formcarry

Nusu Alabuga founded formcarry in 2017 and still runs it: the ingest pipeline, the spam filtering, the email delivery and the incident tracking that watches customers' forms. A product engineer by trade, with years of work in payments, security, invoicing and banking infrastructure.

WebsiteXLinkedInGitHub

Keep reading

LET'S GET STARTED!

Hassle Free Forms

Create your form endpoint and start collecting submissions

for your HTML forms, it only takes 2 minutes to set up your form

formcarry dashboard.
Your email address|