4 min read · Free · No login needed
Forms are how a website collects information: a login, a signup, a contact message, a search box, a payment. The <form> tag wraps all the fields, and when the visitor clicks submit, the browser sends the data to the server address in the form's action attribute.
text — a single line of text (name, city).email — an email address; the browser checks the format for you.password — hides the characters as you type.number — numbers only, with up/down arrows.tel — a phone number; on mobile it opens the number keyboard.date — a date picker.radio — pick one option from a group.checkbox — pick any number of options.Every input needs a <label> connected with the for attribute matching the input's id: <label for="email">Email</label> <input type="email" id="email" name="email">. The label does two things: it tells the visitor what to type, and clicking it focuses the field. Without labels, a form is confusing — and screen readers cannot explain it at all.
<textarea> is for multi-line text (a message). <select> with <option> children is a dropdown. <button type="submit"> sends the form. The required attribute makes a field compulsory — the browser refuses to submit until it is filled.
name attribute is what the server sees. Two fields with the same name will overwrite each other. Always give every input a name — an input without one sends nothing.A form is how a visitor sends information to a website — a name, an email address, a message, a search word. The <form> tag wraps the fields. When the visitor clicks the submit button, the browser collects the values and sends them to the address in the form's action attribute, using the method in its method attribute.
| Attribute | Value | Description |
|---|---|---|
action | a web address | Where the form data is sent. Required for a working form. |
method | get or post | get puts the data in the address bar; post hides it. Use post for anything private. |
name | text | A name for the form itself, used by JavaScript. |
| Type | Value | Description |
|---|---|---|
text | any text | A single line of text — names, cities, subjects. |
password | any text | Text shown as dots, for passwords. |
email | an email address | The browser checks that it looks like an email. |
number | a number | Numbers only, with up and down arrows. |
date | a date | Shows a date picker. |
checkbox | on / off | A tick box — several can be ticked at once. |
radio | one choice | A round button — only one in a group can be chosen. |
submit | — | The button that sends the form. |
A label is connected to its input with the for attribute, which must match the input's id. Clicking the label then focuses the input — a small thing that makes forms much easier to use:
<label for="email">Email:</label> <input type="email" id="email" name="email" required>
name attribute on an input is what gets sent to the server. An input without a name is invisible to the server — its value is never sent, even if the visitor typed in it. Every input that should send data needs a name.required to fields the visitor must fill in, like name and email. The browser then stops the form and shows a message if they are left empty — no JavaScript needed.<label> — a form without labels is hard to use, and screen readers cannot explain the fields.name attribute on inputs — the server receives nothing from those fields.method="get" for a password form — the password would appear in the address bar. Use post.type="submit" — the form will not send.<form action="/submit.php" method="post"> — wraps all the fields. action is where the data goes, and post keeps it out of the address bar.<label for="name">Your Name:</label> — the label for the first field. Its for matches the input's id, so clicking the label focuses the field.<input type="text" ... required> — a one-line text box for the name. required makes the browser refuse to submit until it is filled.<input type="email" ...> — an email field. The browser checks the format for you before the form is sent.<select> with three <option> children — a dropdown. The visitor picks one course: HTML, CSS or JavaScript.<button type="submit">Submit</button> — sends the form. Without type="submit", the button would do nothing.<!DOCTYPE html>
<html>
<head>
<title>Forms</title>
</head>
<body>
<form action="/submit.php" method="post">
<label for="name">Your Name:</label><br>
<input type="text" id="name" name="name" required><br><br>
<label for="email">Email:</label><br>
<input type="email" id="email" name="email" required><br><br>
<label for="course">Course:</label><br>
<select id="course" name="course">
<option value="html">HTML</option>
<option value="css">CSS</option>
<option value="js">JavaScript</option>
</select><br><br>
<button type="submit">Submit</button>
</form>
</body>
</html>
Change the code below and press Run to see the result instantly. No file to save, no login needed.
The questions learners ask most about this lesson — read the question, then open it to see the answer.
It collects information from a visitor, such as a login, signup, contact message or search, and sends it to the server address in action.
The label tells the visitor what to type and clicking it focuses the field, and without it screen readers cannot explain the form.
The server receives nothing from that field, because name is what gets sent to the server.
AI can write code for you, but it cannot think for you. When you learn HTML yourself, your brain builds the real skill: you understand why a page looks the way it does, you can fix it when it breaks, and you can answer it in an exam or an interview without help. That is the skill that gets you a job — not a copied answer.
Finish all 35 lessons, pass the test (80%), pay ₹10 and get your certificate.
Take the testPrefer watching? Video courses teach the same topics step by step.
Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.
Browse all coursesAsk about courses, website & more
Request human callback:
Please log in to download. You will stay on this page after logging in!
New here? Register now →