HTML input type attributes
Examples
HTML form with two different input types, text and submit:
用户名: <input type="text" name="usrname"><br>
<input type="submit" value="提交">
try it"
(See bottom of this page for more examples)
Browser Support
All major browsers support the type attribute. However, not all major browsers support all the different input types can work in all major browsers.
See below for each input type of browser support.
Definition and Usage
<Input> type attribute specifies the type of element you want to display.
The default type is: text.
Note: This attribute is not required, but we think you should always use it.
Differences between HTML 4.01 and HTML5
The following input types are new in HTML5 type: color, date, datetime, datetime-local, month, week, time, email, number, range, search, tel and url.
grammar
Property Value
值 | 描述 |
---|---|
button | 定义可点击的按钮(通常与 JavaScript 一起使用来启动脚本)。 |
checkbox | 定义复选框。 |
color New | 定义拾色器。 |
date New | 定义 date 控件(包括年、月、日,不包括时间)。 |
datetime New | 定义 date 和 time 控件(包括年、月、日、时、分、秒、几分之一秒,基于 UTC 时区)。 |
datetime-local New | 定义 date 和 time 控件(包括年、月、日、时、分、秒、几分之一秒,不带时区)。 |
email New | 定义用于 e-mail 地址的字段。 |
file | 定义文件选择字段和 "浏览..." 按钮,供文件上传。 |
hidden | 定义隐藏输入字段。 |
image | 定义图像作为提交按钮。 |
month New | 定义 month 和 year 控件(不带时区)。 |
number New | 定义用于输入数字的字段。 |
password | 定义密码字段(字段中的字符会被遮蔽)。 |
radio | 定义单选按钮。 |
range New | 定义用于精确值不重要的输入数字的控件(比如 slider 控件)。 |
reset | 定义重置按钮(重置所有的表单值为默认值)。 |
search New | 定义用于输入搜索字符串的文本字段。 |
submit | 定义提交按钮。 |
tel New | 定义用于输入电话号码的字段。 |
text | 默认。定义一个单行的文本字段(默认宽度为 20 个字符)。 |
time New | 定义用于输入时间的控件(不带时区)。 |
url New | 定义用于输入 URL 的字段。 |
week New | 定义 week 和 year 控件(不带时区)。 |
Examples
Input Type: button
Examples
Definition of clickable buttons, when the user clicks a button to start a period of JavaScript:
try it"
Input Type: checkbox
Examples
Box allows the user to select one or more options in a number of choices:
<input type="checkbox" name="vehicle[]" value="Car"> 我有一辆小轿车<br>
<input type="checkbox" name="vehicle[]" value="Boat"> 我有一艘船<br>
try it"
Input Type: color
Examples
Choose a color from the color picker:
try it"
Input type: date
Input Type: datetime
Examples
Define the date and time controls (with time zone):
try it"
Input Type: datetime-local
Examples
Define the date and time controls (without time zone):
try it"
Input Type: email
Examples
Field Definitions for the e-mail address (when the form is submitted automatically to the value of the email field to verify):
try it"
Tip: iPhone Safari browser will recognize the email input type, then change the touch screen keyboard to adapt to it (add @ and .com options).
Input type: file
Examples
To define file selection field and a "Browse ..." button, for file upload:
try it"
Input Type: hidden
Examples
Definition of hidden fields, hidden fields are not visible to the user. Hidden fields often store a default value, or change their values by the JavaScript:
try it"
Input Type: image
Examples
Custom image as the submit button:
try it"
Input Type: month
Examples
Define the month and year control (without time zone):
try it"
Input Type: number
Examples
Enter a number to define the fields for (you can set the acceptable limit numbers):
try it"
Please use the following attributes to specify restrictions:
- MAX - the maximum allowed by regulations.
- min - the minimum allowed by regulations.
- STEP - requirements for legal digital interval.
- value The - specified default.
Input Type: password
Examples
Define password fields (password fields are masked characters):
try it"
Input Type: radio
Examples
It allows the user to select an option in a number of choices:
<input type="radio" name="gender" value="女"> 女
try it"
Input Type: range
Examples
It defines the exact value is not important input digital control (such as slider controls). You can also set limits acceptable numbers:
try it"
Please use the following attributes to specify restrictions:
- MAX - the maximum allowed by regulations.
- min - the minimum allowed by regulations.
- STEP - requirements for legal digital interval.
- value The - specified default.
Input type: reset
Tip: Be careful using the reset button!For users, accidentally clicked on the Reset button is a very annoying thing.
Input Type: search
Examples
Defined search field (for example, site search or Google search, etc.):
try it"
Input Type: submit
Input Type: tel
Input Type: text
Examples
The user can define two to enter a single line of text in a text field:
Last name: <input type="text" name="lname"><br>
try it"
Input Type: time
Examples
Enter the time of the definition of control is used (without time zone):
try it"
Input Type: url
Tip: iPhone Safari browser will recognize the url input type, then change the touch screen keyboard to adapt to it (add .com option).
Input type: week
Examples
Definition of week and year control (without time zone):
try it"
HTML <input> tag