content logo

Learn HTML:

html input tag

When writing in HTML, 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, as well as related attributes and browser compatibility.

Note: The <input> tag belongs to a group of tags called form elements.

Example code

<form action="test_form.asp" method="get">
  Name: <input type="text" name="name"><br>
  E-mail: <input type="text" name="email"><br>
  <input type="submit" value="Submit">
</form>

Example result

Name: 
E-mail: 

 

Attributes

Within an HTML tag, an attribute dictates certain aspects of an HTML element. Attributes are made up of a name and value pair; all tags support standard attributes. The following table shows all of the current unique HTML attributes for the <input> tag, as well as a description of each.

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) an <input> element belongs to
formaction Designates the URL 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 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 into an <input> element
name Designates a name for the <input> element
pattern Designates a regular expression that an <input> element's value is checked against
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 he 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

A deprecated attribute is one that may function currently, but is not supported in going forward. While the attribute may work with the current version of HTML, it will eventually be phased out. It is better to avoid using these attributes to help future-proof your website.

Attribute Description
align Designates the alignment of the <input> element with respect to the content around it
#

HTML Input Example

#

HTML Input Code

#

HTML Input Tutorial