Understanding HTML forms
Inside this lesson
- What a form does
- The <form> element, action, and method
- GET vs POST
- Why every field needs a name
Short answer
An HTML form collects input from visitors, like an inquiry, an order, or a search. The <form> element wraps the fields. Its action says where to send the data and its method says how: GET for searches, POST for messages and orders. Each field needs a name, or its value is not sent.
What forms do
- Contact and inquiry forms
- Order and booking forms
- Search boxes
- Newsletter signups
- Login pages
HTML builds the form. A server or form service receives and processes the data. HTML alone cannot send emails or save data.
The form element
<form action="/send-inquiry" method="post">
<label for="name">Your name</label>
<input type="text" id="name" name="customer_name">
<button type="submit">Send inquiry</button>
</form>
action: the URL that receives the data.method: get or post.name: the label the server sees, like customer_name=Ana.
GET vs POST
| GET | POST | |
|---|---|---|
| Where data goes | In the URL: ?q=pili+tarts | In the request body, not the URL |
| Good for | Searches and filters | Messages, orders, logins |
| Bookmarkable? | Yes | No |
| Safe for passwords? | No | Yes, with HTTPS |
How submission works
- The visitor fills in the fields and clicks the submit button.
- The browser checks built-in rules, like required fields.
- The browser sends name and value pairs to the action URL.
- The server processes the data and returns a thank you page.
If you do not have a server, form services like Formspree, Netlify Forms, or Google Forms can receive submissions for you.
Try it: make a search form
Set method to get, give the input a name of q, and press the button. The preview is sandboxed, so the submit will not go anywhere. Check the code.
Live preview
Quick quiz
Common mistakes
- Missing name attributes. The server receives nothing for that field.
- GET for private data. GET puts values in the URL, history, and logs.
- Forms with no thank you message. Visitors are not sure their message was sent.
Your action
Tick each item when you can do it. Your progress saves on this device.
Key terms
- <form>
- The container for form controls.
- action
- The URL that receives form data.
- method
- How data is sent: get or post.
- name attribute
- The key sent with a field's value.
- GET
- Sends form data in the URL.
- POST
- Sends form data in the request body.
Questions beginners ask
Can I use a form on a static site?
Yes, with a form service like Formspree or Netlify Forms.
Is a Google Form an HTML form?
Google builds it with HTML, and you can embed it with an iframe.
What is form spam?
Bots submit junk. Services add spam filters and honeypot fields.
Related lessons
Need a website built or fixed while you practice? The team at Remar Digital can help.