Forms
Forms collect input from visitors: names, email addresses, choices and more. <input> is the most common form element, and its type attribute decides what kind of input it is.
Every input should have a <label>. Linking the label to the input with matching for and id values lets visitors tap the label to focus the box.
Forms are how websites talk back: sign-up pages, search boxes, checkout pages, contact forms, feedback surveys. When a visitor submits a form, the browser collects the values and sends them to a server, which saves them or replies.
Choosing the right type makes forms much easier on phones: email shows a keyboard with @, tel a number pad, date a calendar. Other useful elements are <textarea> for long text, <select> for a drop-down, and radio buttons and checkboxes for choices.
<!DOCTYPE html>
<html>
<body>
<form onsubmit="event.preventDefault(); document.getElementById('msg').textContent = 'Thanks, ' + document.getElementById('name').value + '!'">
<label for="name">Your name</label><br>
<input id="name" type="text" required><br><br>
<label for="city">City</label><br>
<select id="city">
<option>Delhi</option>
<option>Patna</option>
<option>Mumbai</option>
</select><br><br>
<input id="news" type="checkbox">
<label for="news">Send me offers</label><br><br>
<button type="submit">Submit</button>
</form>
<p id="msg"></p>
</body>
</html>▶ Try it yourselftype="email",type="number"andtype="date"give mobile users the right keyboard or picker.requiredstops the form being sent while the box is empty.- Real forms send data to a server, which must check it again; never trust browser checks alone.
<form>collects input;<input type="...">decides the kind of input.- Always connect a
<label>to each input withforandid. - Browser checks like
requiredhelp, but the server must check again.
