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">
  • <input type="range">
the default value of the type attribute is "text"

Input Type Text

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

<input type="text" id="fname" name="fname"><br>

<input type="text" id="lname" name="lname">

Output:

First name:

Last name:

Input Type Password

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

 <input type="text" id="username" name="username"><br>

  <input type="password" id="pwd" name="pwd">

Output:

Username:

Password:

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:
  <input type="text"> Firstname <br>
  <input type="text">Lastname<br>
  <input type="submit" value="Submit">

Output:

First name:

Last name:


Input Type Reset

<input type="reset"> defines a reset button that will reset all form values to their default values:

  <input type="text"> Firstname <br>
  <input type="text">Lastname<br>
  <input type="submit" value="Submit">
  <input type="reset">

Output:

First name:

Last name:


 

Input Type Radio

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

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

  <input type="radio"> HTML

  <input type="radio"> CSS

  <input type="radio"JavaScript

Output:

 
 
 

Input Type Check Box

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

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

  <input type="checkbox">Bike
  <input type="checkbox">Car
  <input type="checkbox">Boat

Output

 
 
 

Input Type File

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

 <input type="file" id="myfile" name="myfile">

Output:

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.

<input type="color" id="favcolor" name="favcolor"

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.

  <input type="date" id="birthday" name="birthday">

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.

  <input type="datetime-local" id="birthdaytime" name="birthdaytime">

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.

 <input type="email" id="email" name="email">

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.

<input type="image" src="img_submit.gif" alt="Submit" width="48" height="48"

Input Type Hidden

The <input type="hidden"> defines a hidden input field (not visible to a user).

A hidden field lets web developers include data that cannot be seen or modified by users when a form is submitted.

A hidden field often stores what database record that needs to be updated when the form is submitted.

  <input type="text" id="fname" name="fname"><br><br>
  <input type="hidden" id="custId" name="custId" value="3487">             
<input type="submit" value="Submit">

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.

  <input type="month" id="bdaymonth" name="bdaymonth">

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:

  <input type="number" id="quantity" name="quantity" min="1" max="5">

Input Type Range

The <input type="range"> defines a control for entering a number whose exact value is not important (like a slider control). Default range is 0 to 100. However, you can set restrictions on what numbers are accepted with the minmax, and step attributes:

  <input type="range" id="vol" name="vol" min="0" max="50">

Input Type Search

The <input type="search"> is used for search fields (a search field behaves like a regular text field).

  <input type="search" id="gsearch" name="gsearch">

Input Type Tel

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

  <input type="tel" id="phone" name="phone" pattern="[0-9]{3}-[0-9]{2}-[0-9]{3}">

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.

  <input type="time" id="appt" name="appt">

Input Type Url

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

Depending on browser support, the url field can be automatically validated when submitted.

Some smartphones recognize the url type, and adds ".com" to the keyboard to match url input.

  <input type="url" id="homepage" name="homepage">

Input Type Week

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

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

<input type="week" id="week" name="week">