| Depr. | Empty | Version |
|---|---|---|
| No | Yes | HTML 2 |
| IE5.5+ | FF1+ | SA1.3+ | OP9.2+ | CH2+ |
|---|---|---|---|---|
| Full | Full | Full | Full | Full |
Syntax
Description
Describing the
input element simply is not straightforward, as there
is much variation in the way an input appears—and the
attributes it uses or requires—depending on the
type attribute specified. But whatever the
type, the feature that’s common to all
input elements is that they allow users to enter
data.
The specific features of each kind of input are covered in the
type attribute
section of this reference. Other type-specific attributes are
indicated as such in their own sections.
In addition to the standard
attributes listed in the syntax section, there is another attribute that
you might come across that is IE-specific,
autocomplete with values of "on"
or "off". As its name might suggest, the intention is
to allow the browser to remember and complete form fields for you.
However, because it is not cross-browser safe and is also ignored anyway
under certain circumstances (if the page was delivered over HTTPS or was
delivered with headers or a META tag that prevents caching), it is not the
most useful/reliable attribute to use on form inputs.
Example
Here’s a simple text
input (see type for other
input examples):
<form> <label for="firstname">First name</label> <input type="text" name="firstname" id="firstname"/> </form>
Use This For …
The
input element is used to capture user information. The
kind of control that’s used will vary on a case-by-case basis, as
explained in type.
Compatibility
| Internet Explorer | Firefox | Safari | Opera | Chrome | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 5.5 | 6.0 | 7.0 | 8.0 | 1.0 | 1.5 | 2.0 | 3.0 | 3.5 | 1.3 | 2.0 | 3.1 | 4.0 | 9.2 | 9.5 | 10.0 | 2.0 |
| Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full |
It causes no compatibility issues, and has excellent support across all tested browsers.
In this Section
- accept
defines the types of files that may be uploaded - accesskey
assignment of a key to put focus on this form control - align
specifies the alignment or position of an image input - alt
defines alternative text for image input types - checked
preselects the checkbox or radio input to which the attribute is applied - disabled
disables the input so that it can’t be used - maxlength
defines the maximum length (in characters) that the input can accept - name
defines a name by which the input can be referenced - readonly
prevents the input data or selection state from being cleared or changed - size
specifies the width of input fields - src
defines the location (or source) of the image input - tabindex
indicates the order in the logical tabbing sequence for this control - type
defines the type of the input control - usemap
defines a client-side image map for input elements of type image - value
sets the predefined value of the input control