Slide 2.17: HTML lists
Slide 2.19: HTML forms and input (cont.)
Home

HTML Forms and Input


HTML forms are used to select different kinds of user input. A form is an area that can contain form elements. Form elements are elements that allow the user to enter information (like text fields, textarea fields, radio buttons, checkboxes, etc.) in a form.
 <form>
   <input>
   <input>
 </form>

A form is defined with the <form> tag. The most used form tag is the <input> tag. The type of input is specified with the type attribute. The most commonly used input types are explained below.

Text Fields
They are for users to type letters, numbers, etc. in a form.

HTML Script Web Display
 <form>
  First name: 
  <input type="text" name="firstname" />
  Last name: 
  <input type="text" name="lastname" />
 </form>
First name:

Last name:

Note that the form itself is not visible. Also note that in most browsers, the width of the text field is 20 characters by default.

Radio Buttons
Radio buttons are used when you want the user to select one of a limited number of choices. Note that only one option can be chosen.

HTML Script Web Display
 <form>
  <input type="radio" name="sex" value="male" /> Male
  <input type="radio" name="sex" value="female" /> Female
 </form>
  Male
  Female


Demonstration
The following demonstration shows how the HTML script is displayed on the Web.