New Input Types in HTML5

This chapter covers these new input types in detail:

Note:

  • color
  • date
  • datetime
  • datetime-local
  • email
  • month
  • number
  • range
  • search
  • tel
  • time
  • url
  • week

Not all mainstream browsers support the new input types, but you can already use them in all mainstream browsers. Even if they are not supported, they will still display as regular text fields.Not all mainstream browsers support the new input types, but you can already use them in all mainstream browsers. They will still display as a regular text field even if they are not supported.


Input Type: color

The color type is used in input fields to select colors, as shown below:

Opera Safari Chrome Firefox Internet Explorer

Example

Choose a color from the color picker:

Choose your favorite color: <input type="color" name="favcolor">

Try it out »


Input Type: date

The date type allows you to select a date from a date picker.

Opera Safari Chrome Firefox Internet Explorer

Example

Define a date controller:

Birthday: <input type="date" name="bday">

Try it out »


Input Type: datetime

The datetime type allows you to select a date (UTC time).

OperaSafariChromeFirefoxInternet Explorer

Example

Define a date and time controller (local time):

Birthday (date and time): <input type="datetime" name="bdaytime">

Try it out »


Input Type: datetime-local

The datetime-local type allows you to select a date and time (no time zone).

OperaSafariChromeFirefoxInternet Explorer

Example

Define a date and time (no time zone):

Birthday (date and time): <input type="datetime-local" name="bdaytime">

Try it out »


Input Type: email

The email type is used for input fields that should contain email addresses.

OperaSafariChromeFirefoxInternet Explorer

Example

When submitting the form, the email field automatically validates the value to ensure it is valid:

E-mail: <input type="email" name="email">

Try it out »

Note:The Safari browser on iPhone supports the email input type and provides a touch screen keyboard that complements it (adding @ and .com options).


Input Type: month

The month type allows you to select a month.

OperaSafariChromeFirefoxInternet Explorer

Example

Define a month and year (no time zone):

Birthday (month and year): <input type="month" name="bdaymonth">

Try it out »


Input Type: number

The number type is used for input fields that should contain numerical values.

You can also set limits on the numbers that can be accepted:

OperaSafariChromeFirefoxInternet Explorer

Example

Define a numerical input field (with limits):

Quantity (1 to 5): <input type="number" name="quantity" min="1" max="5">

Try it out »

Use the following attributes to set limits on the number type:

Attributes Description
disabled To make the input field disabled
max To set the maximum value
maxlength To set the maximum character length
min To set the minimum value
pattern To set the pattern for input validation
readonly To make the input field read-only
required To make the input field required
size To set the visible character count
step To set the legal numeric interval
value To set the default value

Try it out with all limit attributesTry it out


Input Type: range

The range type is used for input fields that should contain a range of numeric values.

The range type displays as a slider.

OperaSafariChromeFirefoxInternet Explorer

Example

Define a slider input field (not requiring very precise values):

<input type="range" name="points" min="1" max="10">

Try it out »

Use the following attributes to set limits on the number type:

  • max - To set the maximum value
  • min - To set the minimum value
  • step - To set the legal numeric interval
  • value - To set the default value

Input Type: search

The search type is used for search fields, such as site search or Google search.

OperaSafariChromeFirefoxInternet Explorer

Example

Define a search field (similar to site search or Google search):

Search Google: <input type="search" name="googlesearch">

Try it out »


Input Type: tel

OperaSafariChromeFirefoxInternet Explorer

Example

Define a phone number input field:

Phone number: <input type="tel" name="usrtel">

Try it out »


Input Type: time

The time type allows you to select a time.

OperaSafariChromeFirefoxInternet Explorer

Example

Define a time input field (no time zone):

Select time: <input type="time" name="usr_time">

Try it out »


Input Type: url

The url type is used for input fields that should contain URL addresses.

When submitting the form, the url field automatically validates the value.

OperaSafariChromeFirefoxInternet Explorer

Example

Define a URL input field:

Add your homepage: <input type="url" name="homepage">

Try it out »

Note:The Safari browser on iPhone supports the url input type and provides a touch screen keyboard that complements it (adding .com options).


Input Type: week

The week type allows you to select a week and year.

OperaSafariChromeFirefoxInternet Explorer

Example

Define a week and year (no time zone):

Select week: <input type="week" name="week_year">

Try it out »


HTML5 <input> Tag

Tag Description
<input> Description of the input element
Other Extensions