Forms
Ask the reader for information with labelled boxes and a button.
Your HTML is drawn by your own browser, inside this tab. Nothing to install.
A box to type in
<input> is a box the reader can type in. Like <img>, it has no closing tag.
Its type attribute says what kind of answer is expected. text is plain text, email is an email address, and number is a number.
The browser uses the type to help: a phone shows a different keyboard for an email address than for a number.
<input type="text">
<input type="email">Saying what a box is for
A box on its own does not say what to type. <label> holds the words that describe it.
The label and the box are joined by a name: the input gets an id, and the label's for attribute repeats it.
Once they are joined, clicking the words puts the cursor in the box, and a screen reader says the words when the box is reached.
<label for="name">Your name</label>
<input type="text" id="name">Your turn: a labelled box
Ask for an email address.
Practice task
Add an email input with the id email, and a label for it that says Email address.
Your answer is run and checked in the lesson. Create a free account to try it.
A form and its button
<form> wraps the boxes that are sent together.
<button> inside a form sends it. The text between the button's tags is what the button says.
Each input also gets a name. That is the name its answer is sent under.
<form>
<label for="card">Card number</label>
<input type="text" id="card" name="card">
<button>Renew my books</button>
</form>Your turn: a small form
Put a box and a button in a form.
Practice task
Write a form that holds a text input with the name title, and a button that says Search.
Your answer is run and checked in the lesson. Create a free account to try it.