input tag
The input tag, which, when implemented in the code, is written like this - <input>, is an HTML tag that belongs to forms and input tags. Form and Input HTML tags are used to create interactive website elements, hence the name of the category. It includes object such as HTML drop-downs, buttons etc.
<input> creates an input field inside a form defined by the <form> tag. This tag is supported in the current version of HTML, which is HTML5.
Browser support
Here you can see whether <input> is supported by a certain browser, and, if yes, starting from which version it is supported.
Chrome | Firefox | Edge | Opera | Safari |
---|---|---|---|---|
Is supported | Is supported | Is supported | Is supported | Is supported |
Attributes and values
An attribute is a piece of additional information about a tag. While tags denote the type of objects they mark or create, attributes set the parameters of these objects. These parameters can include anything from the types of possible interactions to its visual style to its actual contents.
Values indicate how a certain attribute is actually implemented, if there is a number of ways it can happen.
What attributes are actually allowed in a certain tag depends on the tag itself. Much like possible attributes depend on a tag, possible values depend on an attribute.
The <input> tag supports the following attributes (with their respective values):
Attribute | Value | Description |
---|---|---|
align |
| Specifies the alignment of an image input (only for type="image") (Not Supported in HTML5) |
accept |
| Specifies the types of files that the server accepts (only for type="file") |
alt | text | Specifies an alternate text for images (only for type="image") |
autocomplete |
| Specifies whether an <input> element should have autocomplete enabled |
autofocus | autofocus | Specifies that an <input> element should automatically get focus when the page loads |
checked | checked | Specifies that an <input> element should be pre-selected when the page loads (for type="checkbox" or type="radio") |
dirname | inputname.dir | Specifies that the text direction will be submitted |
disabled | disabled | Specifies that an <input> element should be disabled |
form | form_id | Specifies one or more forms the <input> element belongs to |
URL | URL | Specifies the URL of the file that will process the input control when the form is submitted (for type="submit" and type="image") |
|
| Specifies how the form-data should be encoded when submitting it to the server (for type="submit" and type="image") |
|
| Defines the HTTP method for sending data to the action URL (for type="submit" and type="image") |
formnovalidate | formnovalidate | Defines that form elements should not be validated when submitted |
height | pixels | Specifies the height of an <input> element (only for type="image") |
list | datalist_id | Refers to a <datalist> element that contains pre-defined options for an <input> element |
max |
| Specifies the maximum value for an <input> element |
maxlength | number | Specifies the maximum number of characters allowed in an <input> element |
min |
| Specifies a minimum value for an <input> element |
multiple | multiple | Specifies that a user can enter more than one value in an <input> element |
width | pixels | Specifies the width of an <input> element (only for type=image) |
type |
| Specifies the type <input> element to display |
readonly | readonly | Specifies that an input field is read-only |
step | number | Specifies the legal number intervals for an input field |
placeholder | text | Specifies a short hint that describes the expected value of an <input> element |
pattern | regexp | Specifies a regular expression that an <input> element’s value is checked against |
value | text | Specifies the value of an <input> element |
Global Attributes
Global attributes are HTML tag attributes that can be used by any tag, hence the name "global". They are in contrast to unique attributes that are tag-specific.
<input> supports global attributes.
Event Attributes
Event attributes are HTML tag attributes that allow triggering actions upon specific conditions, hence the name "event". Other types of attributes, namely global and unique attributes, can also trigger actions, but the difference is that even attributes allow calling scripts, such as JavaScript functions, while most other attributes only support a certain type of action.
<input> supports event attributes.