Curriculum
Course: HTML Basic
Login

Curriculum

HTML Basic

HTML Introduction

0/1

HTML Editors

0/1

HTML Elements

0/1

HTML Attributes

0/1

HTML Headings

0/1

HTML Paragraphs

0/1

HTML Styles

0/1

HTML Formatting

0/1

HTML Quotation

0/1

HTML Comments

0/1

HTML Colors

0/1

HTML Favicon

0/1

HTML Page Title

0/1

HTML Block and Inline

0/1

HTML Iframes

0/1

HTML Java Script

0/1

HTML File Paths

0/1

HTML - The Head Element

0/1

HTML Style Guide

0/1

HTML Entities

0/1

HTML Symbols

0/1
Text lesson

HTML Forms

Typically, the user input is transmitted to a server for further processing.

 

The <form> Element

The HTML <form> element is employed to generate an HTML form for user input:

<form>
.
form elements
.
</form>

The <form> element serves as a container for various types of input elements, including text fields, checkboxes, radio buttons, submit buttons, and more.

All the distinct form elements are discussed in detail in this chapter: HTML Form Elements.

The <input> Element

The HTML <input> element stands out as the most commonly utilized form element.

An <input> element can manifest in numerous formats, contingent upon the type attribute.

Here are several examples:

Type

Description

<input type=”text”>

Presents a single-line text input field

<input type=”radio”>

Presents a radio button (for selecting one of many choices)

<input type=”checkbox”>

Presents a checkbox (for selecting zero or more of many choices)

<input type=”submit”>

Presents a submit button (for submitting the form)

<input type=”button”>

Prsents a clickable button

Text Fields

The <input type=”text”> specifies a single-line input field designed for textual input.

Example

A form featuring text input fields:

<form>
  <label for=”fname”>First name:</label><br>
  <input type=”text” id=”fname” name=”fname”><br>
  <label for=”lname”>Last name:</label><br>
  <input type=”text” id=”lname” name=”lname”>
</form>

The <label> Element

Notice the utilization of the <label> element in the example above.

The <label> tag is employed to define a label for numerous form elements.

It proves beneficial for screen-reader users, as the label is audibly read aloud when the user focuses on the input element.

Moreover, the <label> element aids users who may struggle to click on very small areas, such as radio buttons or checkboxes, as clicking the text within the <label> element toggles the associated radio button or checkbox.

To link them together, the for attribute of the <label> tag should match the id attribute of the <input> element.

Radio Buttons

The <input type=”radio”> creates a radio button.

Radio buttons enable users to choose ONE option from a set of limited choices.

Example

A form featuring radio buttons:

<p>Choose your favorite Web language:</p>

<form>
  <input type=”radio” id=”html” name=”fav_language” value=”HTML”>
  <label for=”html”>HTML</label><br>
  <input type=”radio” id=”css” name=”fav_language” value=”CSS”>
  <label for=”css”>CSS</label><br>
  <input type=”radio” id=”javascript” name=”fav_language” value=”JavaScript”>
  <label for=”javascript”>JavaScript</label>
</form>

Checkboxes

The <input type=”checkbox”> creates a checkbox.

Checkboxes enable users to select ZERO or MORE options from a finite set of choices.

Example

A form featuring checkboxes:

<form>
  <input type=”checkbox” id=”vehicle1″ name=”vehicle1″ value=”Bike”>
  <label for=”vehicle1″> I have a bike</label><br>
  <input type=”checkbox” id=”vehicle2″ name=”vehicle2″ value=”Car”>
  <label for=”vehicle2″> I have a car</label><br>
  <input type=”checkbox” id=”vehicle3″ name=”vehicle3″ value=”Boat”>
  <label for=”vehicle3″> I have a boat</label>
</form>

The Submit Button

The <input type=”submit”> creates a button to submit the form data to a form-handler.

Usually, the form-handler refers to a file on the server containing a script to process input data.

The form-handler’s location is specified in the form’s action attribute.

Example

A form featuring a submit button:

<form action=”/action_page.php”>
  <label for=”fname”>First name:</label><br>
  <input type=”text” id=”fname” name=”fname” value=”John”><br>
  <label for=”lname”>Last name:</label><br>
  <input type=”text” id=”lname” name=”lname” value=”Doe”><br><br>
  <input type=”submit” value=”Submit”>
</form>

The Name Attribute for <input>

It’s important to note that each input field must include a name attribute to be submitted.

If the name attribute is left out, the value of the input field won’t be sent.

Example

In this example, the value of the “First name” input field will not be submitted:

<form action=”/action_page.php”>
  <label for=”fname”>First name:</label><br>
  <input type=”text” id=”fname” value=”John”><br><br>
  <input type=”submit” value=”Submit”>
</form>

 

Click to Learn