First name:
"> First name:
" />
Easy Tutorial
❮ Tag Dialog Att Colgroup Align ❯

HTML <input> Tag

Example

A simple HTML form, containing two text input fields and a submit button:

<form action="demo_form.php">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br>
  <input type="submit" value="Submit">
</form>

Browser Support

Element
<input> Yes Yes Yes Yes Yes

Tag Definition and Usage

The <input> tag specifies an input field where the user can enter data.

The <input> element is used within a <form> element to declare input controls that allow users to input data.

Input fields can vary in many ways, depending on the type attribute.


Tips and Notes

Note: The <input> element is empty, it only contains attributes.

Tip: You can use the <label> element to define labels for <input> elements.


Differences Between HTML 4.01 and HTML5

In HTML 4.01, the "align" attribute was no longer used. It is not supported in HTML5. You can use CSS to define the alignment of <input> elements.

In HTML5, several attributes have been added to <input> and corresponding values have been introduced.


Differences Between HTML and XHTML

In HTML, the <input> tag has no closing tag.

In XHTML, the <input> tag must be properly closed.


Attributes

Attribute Value Description
accept audio/*

video/*

image/* MIME_type | Specifies the types of files that the server accepts (only for type="file") | | align | left

right

top

middle

bottom | Deprecated in HTML5. Specifies the alignment of the image input. (Only for type="image") | | alt | text | Defines alternative text for image inputs. (Only for type="image") | | autocomplete New | on

off | Specifies whether an <input> element should have autocomplete enabled. | | autofocus New | 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. (Only for type="checkbox" or type="radio") | | disabled | disabled | Specifies that an <input> element should be disabled. | | form New | form_id | Specifies the form(s) the <input> element belongs to. | | formaction New | URL | Specifies the URL of the file that will process the input control when the form is submitted. (Only for type="submit" and type="image") | | formenctype New | application/x-www-form-urlencoded

multipart/form-data

text/plain | Specifies how the form-data should be encoded when submitting it to the server. (Only for type="submit" and type="image") | | formmethod New | get

post | Defines the HTTP method for sending form-data to the action URL. (Only for type="submit" and type="image") | post | Defines the HTTP method for sending form data to the action URL. (Only applicable for type="submit" and type="image") | | formnovalidate New | formnovalidate | The formnovalidate attribute overrides the novalidate attribute of the <form> element. | | formtarget New | _blank

_self

_parent

_top framename | Specifies the name or keyword indicating where to display the response that is received after submitting the form. (Only applicable for type="submit" and type="image") | | height New | pixels | Specifies the height of the <input> element. (Only applicable for type="image") | | list New | datalist_id | The attribute references the <datalist> element that contains predefined options for the <input> element. | | max New | number<br>date | The attribute specifies the maximum value for the <input> element. | | maxlength | number | The attribute specifies the maximum number of characters allowed in the <input> element. | | min New | number<br>date | The attribute specifies the minimum value for the <input> element. | | multiple New | multiple | The attribute specifies that the user can enter multiple values into the <input> element. | | name | text | The name attribute specifies the name of the <input> element. | | pattern New | regexp | The pattern attribute specifies a regular expression that is used to validate the value of the <input> element. | | placeholder New | text | The placeholder attribute provides a short hint that describes the expected value of the <input> field. | | readonly | readonly | The readonly attribute specifies that the input field is read-only. | | required New | required | The attribute specifies that the input field must be filled out before submitting the form. | | size | number | The size attribute specifies the visible width of the <input> element in characters. | | src | URL | The src attribute specifies the URL of the image to be displayed as the submit button. (Only applicable for type="image") | | step New | number | The step attribute specifies the legal number intervals for the <input> element. | | type | button <br>checkbox <br>color <br>date <br>datetime <br>datetime-local <br>email <br>file <br>hidden <br>image <br>month <br>number <br>password <br>radio <br>range <br>reset <br>search <br>submit <br>tel <br>text <br>time <br>url <br>week | The type attribute specifies the type of the <input> element to display. | | value | text | Specifies the value of the value attribute for the <input> element. | | width New | pixels | The width attribute specifies the width of the <input> element. (Only applicable for type="image") |


Global Attributes

The <input> tag supports global attributes, see the complete attribute table HTML Global Attributes.


Event Attributes

The <input> tag supports all HTML Event Attributes.

❮ Tag Dialog Att Colgroup Align ❯