Author: Michal Szymanski
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.
<form>
Select your favorite color:
<input type="color" name="favcolor">
</form>
Live preview
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.
<form>
Birthday:
<input type="date" name="bday">
</form>
Live preview
You can also use the min
and max
attributes to add restrictions to dates:
<form>
Enter a date before 1980-01-01:
<input type="date" name="bday" max="1979-12-31"><br>
Enter a date after 2000-01-01:
<input type="date" name="bday" min="2000-01-02"><br>
</form>
Live preview
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.
<form>
Birthday (date and time):
<input type="datetime-local" name="bdaytime">
</form>
Live preview
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 adds ".com" to the keyboard to match email input.
<form>
E-mail:
<input type="email" name="email">
</form>
Live preview
Input Type File
The <input type="file">
defines a file-select field and a "Browse" button for file uploads.
<form>
Select a file: <input type="file" name="myFile">
</form>
Live preview
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.
<form>
Birthday (month and year):
<input type="month" name="bdaymonth">
</form>
Live preview
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:
<form>
Quantity (between 1 and 5):
<input type="number" name="quantity" min="1" max="5">
</form>
Live preview
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 min
, max
,
and step
attributes:
<form>
<input type="range" name="points" min="0" max="10">
</form>
Live preview
Input Type Search
The <input type="search">
is used for search fields (a search field
behaves like a regular text field).
<form>
Search Google:
<input type="search" name="googlesearch">
</form>
Live preview
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.
<form>
Select a time:
<input type="time" name="usr_time">
</form>
Live preview
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.
<form>
Add your homepage:
<input type="url" name="homepage">
</form>
Live preview
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.
<form>
Select a week:
<input type="week" name="week_year">
</form>
Live preview
Previous lesson Next lesson
Spread the word: