HTML <input> tag
When writing in HTML (hypertext markup language), the <input> tag is an inline element used to create both input fields and interactive controls for web-based forms. Nested within a <form> tag, they are useful for allowing the acceptance of user-input data of various types on a website. The following sections contain information about the <input> tag, including an example of it in use, and related attributes and browser compatibility.
The <input> tag belongs to a group of tags called form elements.
Example of <input> code
<form action="script name" method="get">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit" value="Submit">
</form>
The"script name" in the action attribute should be changed to the name and location of your script file. For example, it could be changed to an ASP (Active Server Pages), Perl, PHP (PHP: Hypertext Preprocessor), or Python script file.
Example result
The above example returns you to this page because nothing is used for the action. If you want a working example of the form tag, you can use our search engine found at the top and bottom of every page. For example, enter any computer term in the search to get an immediate definition of that term.
Attributes
All HTML tags support standard attributes that define the settings of an HTML element. In addition to the standard settings, the <input> tag has the following unique attributes.
Attribute | Description |
---|---|
accept | Designates the files types that a server accepts (only used for type="file"). |
alt | Designates an alternate text for images (only used for type="image"). |
autocomplete | Toggles the autocomplete function. |
autofocus | Designates that an <input> element should be the first thing focused when the page loads. |
checked | Designates that an <input> element should be pre-selected when the page loads (for type="checkbox" or type="radio"). |
disabled | Designates that the <input> element is disabled. |
form | Designates the form(s) of where an <input> element belongs. |
formaction | Designates the URL (uniform resource locator) of the file that will process the submitted form data (for type="submit" and type="image"). |
formenctype | Designates how the form data should be encoded upon submission (for type="submit" and type="image"). |
formmethod | Designates the HTTP (hypertext transfer protocol) method to be used when sending data to the formaction URL (for type="submit" and type="image"). |
formnovalidate | Designates that form data should not be validated upon submission. |
formtarget | Designates where to display the response to submitted data (for type="submit" and type="image"). |
height | Designates the height of the <input> element. |
list | Points to a <datalist> element containing options for the <input> element. |
max | Designates the max value of an <input> element. |
maxlength | Designates the max number of characters allowed in an <input> element. |
min | Designates the minimum value of an <input> element. |
multiple | Designates that a user can enter multiple values in an <input> element. |
name | Designates a name for the <input> element. |
pattern | Designates a regular expression that an <input> element's value is used to check. |
placeholder | Designates a message that describes the expected value of an <input> element. |
readonly | Designates that an <input> element is read-only. |
required | Designates that an input field must be filled out before form submission. |
size | Designates how many characters wide an <input> element is. |
src | Designates the URL of the image to use as a submit button. |
step | Designates the allowed number intervals for an input field. |
type | Designates the type of <input> element to display. |
value | Designates the value of an <input> element. |
width | Designates the width of an <input> element. |
Deprecated attributes
In addition to the above attributes, the <input> tag had the following deprecated attributes.
Attribute | Description |
---|---|
align | Designates the alignment of the <input> element with respect to the content around it. |
Compatibility
Edge | Internet Explorer | Firefox | Safari | Opera | Chrome |
---|---|---|---|---|---|
All versions | All versions | All versions | All version | All versions | All versions |
Additional form elements
- <button>
- <datalist>
- <fieldset>
- <keygen>
- <label>
- <legend>
- <optgroup>
- <option>
- <output>
- <select>
- <textarea>
Autocomplete, Browser, Compatibility, HTML datalist tag, HTTP, Nesting, Read-only, Regular expression, URL, Web design terms