In this lesson you will
- Connect every field to a visible label
- Choose input types that help on phones
- Use built-in validation and know its limits
form, label and name
<form> groups fields and sends them when submitted. action is where the data goes and method is how: get puts it in the URL (good for searches), post sends it in the request body (use it for anything that changes data or is private). Without action, the form submits to the current page.
Every field needs a label. <label for="email">Email</label> connects to <input id="email">. Clicking the label then focuses the field (a bigger tap target on phones), and screen readers read the label when the field is focused. Placeholder text is not a label: it disappears when you type and is often too pale to read.
name is the key the browser sends with the value, like email=ali@example.com. A field without a name is not submitted at all, which is a common reason why "the form sends nothing". In the editor below, submitting shows the data in the console.
Console
- Console messages, errors, form data and clicked links appear here.
Press Send with the fields empty: the browser stops you. Fill them in and press Send again: the console shows exactly what would be sent.
Sign in free to read the full lesson
You are reading the free preview. Create a free account (it takes one minute, no password) to unlock the rest of this lesson and track your progress.
Unlocks after sign-in:
- 2 more sections with live code examples
- Common mistakes to avoid
- Hands-on coding exercise with automatic checks
- Practice quiz and the graded lesson test
Free forever. No card, no paywall.
Questions people ask
Can HTML send form data to my email without a server?
Not reliably. action="mailto:..." only opens the visitor’s email app and fails for many people. You need something on a server, your own or a form service, to receive the data and send the email.
How do I change the browser’s validation message?
With JavaScript: setCustomValidity() sets your own message, and the title attribute adds a hint shown with pattern errors in some browsers. Many sites show their own message next to the field instead.
Should I use GET or POST?
GET for searches and filters, because the result can be bookmarked and shared. POST for logins, payments, messages and anything that creates or changes data, so it is not stored in the URL and browser history.
How do I accept Arabic and English names in one field?
Use a plain text input with no pattern that limits letters, and add dir="auto" so the text direction follows what the person types. Avoid rules like "letters A to Z only", which reject real names.
Is a date input reliable on all browsers?
type="date" is supported in all current major browsers. The picker looks different on each one, and the value is always sent as YYYY-MM-DD whatever format the visitor sees.
Sources
Facts in this lesson were checked against these official pages on 20 October 2026.
Code examples stay in English and run in a sandbox on your device. If you spot a mistake, tell us through the contact page.