The HTML <form> Elements

The HTML <form> element can contain one or more of the following form elements:

Go to Forms (Core Concept)

→ View Forms Core Concepts (input, label, textarea, button) 

Details of the following tags are on this page. For details of the above tags, go to Form(core concept).

The <select> Element

The <select> element defines a drop-down list:

Example

Result

The select Element

The select element defines a drop-down list:

 

 

 

The <option> element defines an option that can be selected.

By default, the first item in the drop-down list is selected.

To define a pre-selected option, add the selected attribute to the option:

Example

The <fieldset> and <legend> Elements

The <fieldset> element is used to group related data in a form.

The <legend> element defines a caption for the <fieldset> element.

Example

Result

Grouping Form Data with Fieldset

The fieldset element is used to group related data in a form, and the legend element defines a caption for the fieldset element.

Personalia:




The <datalist> Element

The <datalist> element specifies a list of pre-defined options for an <input> element.

Users will see a drop-down list of the pre-defined options as they input data.

The list attribute of the <input> element, must refer to the id attribute of the <datalist> element.

Example

Result

The datalist Element

The datalist element specifies a list of pre-defined options for an input element.

 

The <output> Element

The <output> element represents the result of a calculation (like one performed by a script).

Example

Result

The output Element

The output element represents the result of a calculation.

 

 100 +  = 97

 

 

HTML Input Types

Here are the different input types you can use in HTML:

  • <input type="button">
  • <input type="checkbox">
  • <input type="color">
  • <input type="date">
  • <input type="datetime-local">
  • <input type="email">
  • <input type="file">
  • <input type="hidden">
  • <input type="image">
  • <input type="month">
  • <input type="number">
  • <input type="password">
  • <input type="radio">
  • <input type="range">
  • <input type="reset">
  • <input type="search">
  • <input type="submit">
  • <input type="tel">
  • <input type="text">
  • <input type="time">
  • <input type="url">
  • <input type="week">

📝 Text Inputs

Input Type Text

<input type="text"> defines a single-line text input field:

Example

Result

Text field

The input type=”text” defines a one-line text input field:

 




Note that the form itself is not visible.

Also note that the default width of a text field is 20 characters.

 

 

Input Type Password

<input type="password"> defines a password field:

Example

Result

Password field

The input type=”password” defines a password field:

 




The characters in a password field are masked (shown as asterisks or circles).

 

Input Type Email

The <input type="email"> is used for input fields that should contain an e-mail address.

Depending on browser support, the e-mail address can be automatically validated when submitted.

Some smartphones recognize the email type, and add “.com” to the keyboard to match email input.

Example

Result

Email Field

The input type=”email” is used for input fields that should contain an e-mail address:

 

 

 

 

Input Type Number

The <input type="number"> defines a numeric input field.

You can also set restrictions on what numbers are accepted.

The following example displays a numeric input field, where you can enter a value from 1 to 5:

Example

 

Result

Number Field

The input type=”number” defines a numeric input field.

You can use the min and max attributes to add numeric restrictions in the input field:

 

 

 

 

🚀 Buttons

Input Type Submit

<input type="submit"> defines a button for submitting form data to a form-handler.

The form-handler is typically a server page with a script for processing input data.

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

Example

Result

Submit Button

The input type=”submit” defines a button for submitting form data to a form-handler:

 




If you click “Submit”, the form-data will be sent to a page called “/action_page.php”.

 

🔘 Selection Inputs

Input Type Radio

<input type="radio"> defines a radio button.

Radio buttons let a user select ONLY ONE of a limited number of choices:

Example

Result

Radio Buttons

The input type=”radio” defines a radio button:

Choose your favorite Web language:

 

 
 
 

 

Input Type Checkbox

<input type="checkbox"> defines a checkbox.

Checkboxes let a user select ZERO or MORE options of a limited number of choices.

Example

Result

Checkboxes

The input type=”checkbox” defines a checkbox:

 

 
 
 

 

🎨 Special Inputs

Input Type Color

The <input type="color"> is used for input fields that should contain a color.

Depending on browser support, a color picker can show up in the input field.

Example

Result

Show a Color Picker

The input type=”color” is used for input fields that should contain a color.

 

 

Note: type=”color” is not supported in Internet Explorer 11.

 

Input Type File

The <input type="file"> defines a file-select field and a “Browse” button for file uploads.

Example

Result

File upload

Show a file-select field which allows a file to be chosen for upload:

 

 

 

 

 

Input Type Image

The <input type="image"> defines an image as a submit button.

The path to the image is specified in the src attribute.

Example

Result

Display an Image as the Submit button

 

 

 

Note: The input type=”image” sends the X and Y coordinates of the click that activated the image button.

 

📅 Date & Time

Input Type Date

The <input type="date"> is used for input fields that should contain a date.

Depending on browser support, a date picker can show up in the input field.

Example

Result

Date Field

The input type=”date” is used for input fields that should contain a date.

 

 

Note: type=”date” is not supported in Internet Explorer 11.

 

Input Type Datetime-local

The <input type="datetime-local"> specifies a date and time input field, with no time zone.

Depending on browser support, a date picker can show up in the input field.

Example

Result

Local Date Field

The input type=”datetime-local” specifies a date and time input field, with no time zone.

 

 

Note: type=”datetime-local” is not supported in Internet Explorer 11.

 

Input Type Month

The <input type="month"> allows the user to select a month and year.

Depending on browser support, a date picker can show up in the input field.

Example

Result

Month Field

The input type=”month” allows the user to select a month and year.

 

 

Note: type=”month” is not supported in Firefox, Safari, or Internet Explorer 11.

 

Input Type Time

The <input type="time"> allows the user to select a time (no time zone).

Depending on browser support, a time picker can show up in the input field.

Example

Result

Show a Time Input Control

The input type=”time” allows the user to select a time (no time zone):

If the browser supports it, a time picker pops up when entering the input field.

 

 

Note: type=”time” is not supported in Internet Explorer 11.