HTML Form Elements


Lesson 28 of 58

HTML forms are built using different types of elements. Each element serves a specific purpose, from text inputs to drop-down lists to buttons. This chapter covers all the form elements you will need.


Common Form Elements

Here are the most important form elements you will use:

  • <input> – Text fields, checkboxes, radio buttons, and more
  • <label> – Labels for form fields (important for accessibility)
  • <select> – Drop-down lists
  • <textarea> – Multi-line text areas
  • <button> – Clickable buttons
  • <fieldset> and <legend> – Group related fields
  • <datalist> – Auto-complete suggestions
  • <output> – Display calculation results

The input Element

The <input> element is the most versatile form element. It can display as many different controls depending on the type attribute.

Various Input Types

The label Element

The <label> element adds a text label to a form field. It is important for accessibility because screen readers read the label aloud. It also makes the form easier to use because clicking the label focuses the input.

Label Example

The select Element (Drop-Down List)

The <select> element creates a drop-down list. Each option is defined with the <option> tag.

Basic Drop-Down List

Pre-selected Option

Use the selected attribute to pre-select an option:

<option value="canada" selected>Canada</option>

Visible Options (size attribute)

Size Attribute Example

Allow Multiple Selections

Multiple Selection Example

The textarea Element (Multi-Line Text)

Textarea Example

The button Element

Button Examples

The fieldset and legend Elements (Grouping Fields)

Fieldset and Legend Example

The datalist Element (Auto-Complete Suggestions)

Datalist Example

The output Element (Display Calculation Results)

Output Example

Quick Summary

  • <input> – Most versatile form element (text, email, password, number, etc.)
  • <label> – Adds labels and improves accessibility (click label focuses input)
  • <select> – Creates drop-down lists with <option> tags
  • <textarea> – Multi-line text input (use for comments, messages)
  • <button> – Clickable button (can contain HTML content)
  • <fieldset> and <legend> – Group related form fields
  • <datalist> – Provides auto-complete suggestions
  • <output> – Displays calculation results

HTML Form Elements Reference

Tag Description
<input>Defines an input control (text, email, password, etc.)
<label>Defines a label for an input element
<select>Defines a drop-down list
<option>Defines an option in a drop-down list
<textarea>Defines a multi-line text input
<button>Defines a clickable button
<fieldset>Groups related elements in a form
<legend>Defines a caption for a fieldset
<datalist>Specifies a list of pre-defined options
<output>Represents the result of a calculation

Lesson 28 of 58