HTML Element: input

The <input> element is possibly the most powerful and versatile of HTML form controls. It can be used for all kinds of things depending on the type of input and the attributes used. 

Example

One element, so many different types.

Syntax

1
<input type="text" placeholder="First name" />
2
<input type="password" placeholder="Password" />
3
<input type="submit" value="Login" />

Result

Browser Support

The <input> tag is supported in all modern browsers. Read more on caniuse.com

Attributes

The <input> tag supports Global Attributes in HTML. Global Attributes are common to all HTML elements and can be used on all of them (though they may not have much of an effect on some of them).

A generic <input> element also supports the following attributes:

  • type: Type of form control.
  • value: Value of the form control.

Many additional attributes are supported based on the type of input being authored.

Input Types

Input elements come in a number of different types to support different types of data that may be entered. Below is a list of the supported types:

  • type=button: Simply a button with no data type
  • type=checkbox: A set of zero or more values from a predefined list that is presented as a checkbox.
  • type=color: A sRGB color with 8-bit red, green, and blue components presented as a color picker.
  • type=date: A data (year, month, day) with no time zone presented as a date control.
  • type=datetime-local: A date and time (year, month, day, hour, minute, second, and fraction of second) with no timezone presented as a date and time control.
  • type=email: An email address or list of email addresses presented as a text control.
  • type=file: Zero or more files each with a MIME type and optionally a filename
  • type=hidden: An arbitrary string hidden from appearance.
  • type=image: A coordinate, relative to a particular image’s size, with the extra semantic that it must be the last value selected and initiates form submission presented as a clickable image or button.
  • type=month: A date consisting of a year and a month with no time zone presented as a month control.
  • type=number: A numerical value presented as a text control with a spinner control.
  • type=password: Text with no line breaks that won’t display sensitive information as a user types.
  • type=radio: An enumerated value presented as a radio button.
  • type=range: A numerical value, with the extra semantic that the exact value is not important presented as a slider control or similar.
  • type=reset: Used to reset a form element and presented as a button.
  • type=search: Text with no line breaks presented as a search control.
  • type=submit: An enumerated value, with the extra semantic that it must be the last value selected and initiates form submission presented as a button.
  • type=tel: Text with no line breaks presented as a text control.
  • type=text: Text with no line breaks presented as a text control.
  • type=time: A time (hour, minute, seconds, fractional seconds) with no time zone presented as a time control.
  • type=url : An absolute URL presented as a text control.
  • type=week: A date consisting of a week-year number and a week number with no time zone presented as a week control.

Content

Inputs don’t support content and are considered a void element.

Mobile Device Considerations

  • Control labeling: For better usability and accessibility label all input controls appropriately.
  • Accessibility: Minimize user typing by specifying input types properly. On mobile devices, different keyboard configurations are displayed depending on the input type currently in focus:
an ordinary text inputan ordinary text inputan ordinary text input

An “ordinary” input with type="text". Notice the dictate option here.

an email type inputan email type inputan email type input

An input with type="email" will make the @ and . symbols quickly accessible for users

an input with type='url'an input with type='url'an input with type='url'

An input with type="url" will display a .com button for quick URL entry

a tel type inputa tel type inputa tel type input

An input with type="tel" will make entering a telephone number super easy.


This content originally appeared on Envato Tuts+ Tutorials and was authored by Andy Leverenz

The <input> element is possibly the most powerful and versatile of HTML form controls. It can be used for all kinds of things depending on the type of input and the attributes used. 

Example

One element, so many different types.

Syntax

1
<input type="text" placeholder="First name" />
2
<input type="password" placeholder="Password" />
3
<input type="submit" value="Login" />

Result

Browser Support

The <input> tag is supported in all modern browsers. Read more on caniuse.com

Attributes

The <input> tag supports Global Attributes in HTML. Global Attributes are common to all HTML elements and can be used on all of them (though they may not have much of an effect on some of them).

A generic <input> element also supports the following attributes:

  • type: Type of form control.
  • value: Value of the form control.

Many additional attributes are supported based on the type of input being authored.

Input Types

Input elements come in a number of different types to support different types of data that may be entered. Below is a list of the supported types:

  • type=button: Simply a button with no data type
  • type=checkbox: A set of zero or more values from a predefined list that is presented as a checkbox.
  • type=color: A sRGB color with 8-bit red, green, and blue components presented as a color picker.
  • type=date: A data (year, month, day) with no time zone presented as a date control.
  • type=datetime-local: A date and time (year, month, day, hour, minute, second, and fraction of second) with no timezone presented as a date and time control.
  • type=email: An email address or list of email addresses presented as a text control.
  • type=file: Zero or more files each with a MIME type and optionally a filename
  • type=hidden: An arbitrary string hidden from appearance.
  • type=image: A coordinate, relative to a particular image’s size, with the extra semantic that it must be the last value selected and initiates form submission presented as a clickable image or button.
  • type=month: A date consisting of a year and a month with no time zone presented as a month control.
  • type=number: A numerical value presented as a text control with a spinner control.
  • type=password: Text with no line breaks that won't display sensitive information as a user types.
  • type=radio: An enumerated value presented as a radio button.
  • type=range: A numerical value, with the extra semantic that the exact value is not important presented as a slider control or similar.
  • type=reset: Used to reset a form element and presented as a button.
  • type=search: Text with no line breaks presented as a search control.
  • type=submit: An enumerated value, with the extra semantic that it must be the last value selected and initiates form submission presented as a button.
  • type=tel: Text with no line breaks presented as a text control.
  • type=text: Text with no line breaks presented as a text control.
  • type=time: A time (hour, minute, seconds, fractional seconds) with no time zone presented as a time control.
  • type=url : An absolute URL presented as a text control.
  • type=week: A date consisting of a week-year number and a week number with no time zone presented as a week control.

Content

Inputs don’t support content and are considered a void element.

Mobile Device Considerations

  • Control labeling: For better usability and accessibility label all input controls appropriately.
  • Accessibility: Minimize user typing by specifying input types properly. On mobile devices, different keyboard configurations are displayed depending on the input type currently in focus:
an ordinary text inputan ordinary text inputan ordinary text input

An “ordinary” input with type="text". Notice the dictate option here.

an email type inputan email type inputan email type input

An input with type="email" will make the @ and . symbols quickly accessible for users

an input with type='url'an input with type='url'an input with type='url'

An input with type="url" will display a .com button for quick URL entry

a tel type inputa tel type inputa tel type input

An input with type="tel" will make entering a telephone number super easy.


This content originally appeared on Envato Tuts+ Tutorials and was authored by Andy Leverenz


Print Share Comment Cite Upload Translate Updates
APA

Andy Leverenz | Sciencx (2023-02-27T14:26:51+00:00) HTML Element: input. Retrieved from https://www.scien.cx/2023/02/27/html-element-input/

MLA
" » HTML Element: input." Andy Leverenz | Sciencx - Monday February 27, 2023, https://www.scien.cx/2023/02/27/html-element-input/
HARVARD
Andy Leverenz | Sciencx Monday February 27, 2023 » HTML Element: input., viewed ,<https://www.scien.cx/2023/02/27/html-element-input/>
VANCOUVER
Andy Leverenz | Sciencx - » HTML Element: input. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/02/27/html-element-input/
CHICAGO
" » HTML Element: input." Andy Leverenz | Sciencx - Accessed . https://www.scien.cx/2023/02/27/html-element-input/
IEEE
" » HTML Element: input." Andy Leverenz | Sciencx [Online]. Available: https://www.scien.cx/2023/02/27/html-element-input/. [Accessed: ]
rf:citation
» HTML Element: input | Andy Leverenz | Sciencx | https://www.scien.cx/2023/02/27/html-element-input/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.