Forms & Controls

HTML <input> element

Build a form with the HTML form generator

Creates a form control whose behavior depends on type. Attributes are applicable by input state, and a visible label is usually necessary. This is a void element. Each type has a different value model, validity constraints and applicable attributes. Associate a visible label, choose the type based on the data rather than its visual appearance, and use name for submitted form data. Native validation improves usability but must not replace server-side validation. A disabled control is normally omitted from submission. It accepts global HTML attributes; individual global features may be inapplicable or restricted.

Formal Syntax & Structure

html syntaxhtml
<input type="text" name="name">

Parameters & Attributes

NameTypeDescription
acceptcomma-separated file typesHints which files a file picker should offer, using extensions, MIME types or supported wildcards. It does not validate uploaded content; check files on the server.
alphabooleanRequests alpha-channel support in a color input. This is a newer feature; do not assume every picker or browser handles transparency.
alttextText alternative for image submit controls; not used on ordinary text inputs.
autocompleteordered autofill tokens or on/offGives the browser the purpose of a form field or controls autofill. Use meaningful tokens such as email or current-password. A browser may still offer password-manager autofill even with off.
checkedbooleanSets the default checked state for a checkbox or radio input. The current checked state is a DOM property and may change independently after user interaction.
colorspaceenumerated: limited-srgb, display-p3Selects the color-space mode for a color input where supported. Use a conventional sRGB hex color when broad interoperability matters.
dirnameform field nameAdds a separate form data entry recording the directionality of a supported text input or textarea. The submitted direction is ltr or rtl.
disabledbooleanDisables supported controls or elements. Disabled form controls are generally not focusable, validated or submitted. The exact effect depends on the element; disabled="false" still disables.
formform element IDAssociates an eligible control with a form elsewhere in the same document, overriding an ancestor form where applicable. Does not automatically associate descendants of a fieldset.
formactionURLOverrides the associated form's submission destination for this submit button or image submit input.
formenctypeform encoding keywordOverrides the associated form's encoding when this submit control initiates submission. Use multipart/form-data for file upload requests.
formmethodenumerated: get, post, dialogOverrides the form submission method for a particular submit control. dialog closes an associated dialog instead of making an ordinary network submission.
formnovalidatebooleanBypasses native constraint validation when the corresponding submit control is used. Server-side validation is still required.
formtargetbrowsing context name or keywordOverrides the target browsing context for the submission initiated by this control.
heightnon-negative integerSets an element-specific height, commonly in CSS pixels. On images, pair it with width matching the intrinsic aspect ratio to reserve layout space. It is not a CSS length with units.
listdatalist IDAssociates a supported input with a datalist of suggestions. It does not restrict the input to the listed values; use select when a closed set is required.
maxnumber or type-specific date/timeSets the upper constraint for applicable input types or the upper bound for meter and progress. Format and defaults depend on the element and input type.
maxlengthnon-negative integerLimits text length in applicable inputs and textareas, measured in UTF-16 code units. It is not a byte limit or a reliable count of user-perceived characters.
minnumber or type-specific date/timeSets the lower constraint for eligible inputs or the lower bound of meter. It must use the type's value syntax; the effect depends on the element.
minlengthnon-negative integerSets the minimum length of user-entered nonempty text in applicable fields, measured in UTF-16 code units. Add required if an empty value must also be invalid.
multiplebooleanAllows multiple files, comma-separated email addresses or multiple select options depending on the element. It does not apply to ordinary text inputs.
namestringProvides an element-specific name: a form field key, radio group name, named frame, metadata key, slot name or other defined purpose. Its meaning depends on the element; it is not a unique DOM identifier.
patternJavaScript regular expression sourceAdds a whole-value pattern constraint to supported text-like inputs. Modern HTML uses Unicode Sets (v flag) semantics. Do not wrap the pattern in slash delimiters; combine with required to reject empty input.
placeholdershort text hintShows a temporary hint when a supported form field is empty. It disappears during entry and is not a substitute for a persistent accessible label.
popovertargetelement IDIdentifies a popover controlled by a button or eligible input button. The target must have the popover attribute; use the ID without #.
popovertargetactionenumerated: toggle, show, hideSpecifies the action a popover invoker performs. The default is toggle. The target must be identified by popovertarget.
readonlybooleanPrevents user editing of eligible inputs and textareas without disabling their normal submission. It does not apply to every control type, and scripts can still alter the value.
requiredbooleanMakes supported form controls subject to a nonempty or selected-value constraint. Radio-group and checkbox behavior differs. It does not perform server-side validation.
sizepositive integerOn applicable text inputs, suggests width in characters; on select, specifies a visible option count. It does not constrain the text length or number of choices.
srcURLSpecifies the resource to load for the given element, such as an image, script or media file. The resource type, loading behavior and security rules depend on the element.
steppositive number or anyDefines allowed value increments for applicable number and date/time inputs. The step base and default depend on the type and min or value. any disables step mismatch validation.
switchbooleanRequests a switch-style presentation for a checkbox in supporting browsers. Its checkbox state and form submission remain the underlying behavior. Use a visible label and test browser support.
typeinput type keywordSelects one of the 22 input states. Missing or invalid type falls back to text. Other attributes apply only to particular states.
valuetype-dependent valueDefault value or submitted value depending on type. A file input cannot be prefilled with a path.
widthnon-negative integerDefines element-specific width, commonly in CSS pixels. On images it can establish an intrinsic aspect ratio together with height; on canvas it sets the bitmap width.
autofocusbooleanRequests initial focus when the document or relevant dialog or popover is shown. Avoid unexpected focus changes that disorient keyboard or screen reader users.
inputmodeenumerated: none, text, decimal, numeric, tel, search, email, urlHints which virtual keyboard layout to present. It does not constrain permitted values or perform validation. Use it for text identifiers that need a numeric keypad.
autocapitalizeenumerated: none, off, sentences, on, words, charactersHints how a virtual keyboard should capitalize text. It is not validation and has no effect on some input types, such as email and password.
autocorrectenumerated: on, offHints whether automatic spelling correction is enabled for editable text. Browser and platform support varies; use off where exact identifiers matter.
enterkeyhintenumerated: enter, done, go, next, previous, search, sendHints which action label or icon a virtual keyboard should show for Enter. It does not implement form submission or navigation.

Return Value

HTMLInputElement

Content model: Empty; this void element cannot contain children and must not have an end tag. No closing tag.

Working Example

Example Snippethtml
<!doctype html><html lang="en">  <head>    <meta charset="utf-8">    <title>HTML example</title>  </head>  <body>    <label for="name">Name</label>    <input id="name" name="name" required>  </body></html>

Browser Compatibility

Minimum supported versions across modern rendering engines

Widely Available (2015)
Blink (modern)
Chrome
1
Yes
EdgeHTML / Blink
Edge
12
Yes
Gecko
Firefox
1
Yes
WebKit
Safari
1
Yes
Presto / Blink
Opera
≤12.1
Yes
Basic input element support; individual input types and attributes have different support.
HTML Living Standard
HTML Reference