HTML, CSS & JS, lesson 4
Forms are how pages ask people for things: a search term, an email address, an order. HTML gives you the controls; the browser handles typing, focus and validation for free.
<input> is a single control. Its type changes what it is: text, email, number,
password, checkbox, date and more. The right type gives people the right keyboard on
phones and basic validation.<label> names a control. Connect it with for set to the input's id. Then clicking the
label focuses the input, and screen readers announce the label. Never leave an input without
one; a is not a label.One exercise to try what you just read.
placeholdername is the key the value is sent under when the form is submitted.required, min, max and maxlength let the browser check values before submitting.For a few options people should see at once, use radio buttons (type="radio") that share a
name. Use a checkbox for a yes/no choice.
Build a <form> with:
id="name" and a <label> connected to it, and make it required.id="email" and a connected label.id="qty", min="1" and max="12", with a connected label.Order.<form>
<label for="name">Your name</label>
<input id="name" name="name" type="text" required>
<label for="qty">How many pancakes?</label>
<input id="qty" name="qty" type="number" min="1" max="12" value="3">
<button type="submit">Order</button>
</form><label for="topping">Topping</label>
<select id="topping" name="topping">
<option>Maple syrup</option>
<option>Berries</option>
</select>