HTML Basics · Lesson 10 of 11

Forms

Forms let visitors type something in: a search, a login, a message. A form is a <form> element with fields inside it:

<form>
  <label for="name">Your name</label>
  <input type="text" id="name" name="name">

  <button type="submit">Send</button>
</form>

Inputs

<input> is an empty element. Its type attribute decides what kind of field it is:

TypeWhat you get
textA one-line text box
emailA text box that checks for an email address
numberA box for numbers, with small up and down arrows
passwordA text box that hides what you type
checkboxA box to tick

The name attribute is the label the data is sent under. Add required to make the browser refuse an empty field.

Labels

Every field needs a <label> that says what to type. Connect the two by giving the input an id and putting the same value in the label's for attribute. Then clicking the label puts the cursor in the field, and screen readers read the label aloud.

Buttons

<button type="submit"> sends the form. On a real site, the form's action attribute says which address receives the data. This preview does not send anything anywhere.

Your Task

  1. Inside the form, add a label and a text input for a name. Connect them with for and id.
  2. Add a label and an input of type email for an email address, connected the same way.
  3. Make the email input required.
  4. Add a submit button with the text Sign Up.
  • The form has a text input with a connected label
  • The form has an input of type email with a connected label
  • The email input is required
  • The form has a submit button that says Sign Up
  • The two inputs have different id values