: The Input (Form Input) Element - HTML - MDN Web Docs

The <input> element is so powerful because of its attributes; the type attribute, described with examples above, being the most important. Since every <input> element, regardless of type, is based on the HTMLInputElement interface, they technically share the exact same set of attributes. However, in reality, most attributes have an effect on only a specific subset of input types. In addition, the way some attributes impact an input depends on the input type, impacting different input types in different ways.

This section provides a table listing all the attributes with a brief description. This table is followed by a list describing each attribute in greater detail, along with which input types they are associated with. Those that are common to most or all input types are defined in greater detail below. Attributes that are unique to particular input types—or attributes which are common to all input types but have special behaviors when used on a given input type—are instead documented on those types' pages.

Attributes for the <input> element include the global HTML attributes and additionally:

Attribute Type(s) Description
accept file Hint for expected file type in file upload controls
alt image alt attribute for the image type. Required for accessibility
autocapitalize all except url, email, and password Controls automatic capitalization in inputted text.
autocomplete all except checkbox, radio, and buttons Hint for form autofill feature
capture file Media capture input method in file upload controls
checked checkbox, radio Whether the command or control is checked
dirname hidden, text, search, url, tel, email Name of form field to use for sending the element's directionality in form submission
disabled all Whether the form control is disabled
form all Associates the control with a form element
formaction image, submit URL to use for form submission
formenctype image, submit Form data set encoding type to use for form submission
formmethod image, submit HTTP method to use for form submission
formnovalidate image, submit Bypass form control validation for form submission
formtarget image, submit Browsing context for form submission
height image Same as height attribute for <img>; vertical dimension
list all except hidden, password, checkbox, radio, and buttons Value of the id attribute of the <datalist> of autocomplete options
max date, month, week, time, datetime-local, number, range Maximum value
maxlength text, search, url, tel, email, password Maximum length (number of characters) of value
min date, month, week, time, datetime-local, number, range Minimum value
minlength text, search, url, tel, email, password Minimum length (number of characters) of value
multiple email, file Boolean. Whether to allow multiple values
name all Name of the form control. Submitted with the form as part of a name/value pair
pattern text, search, url, tel, email, password Pattern the value must match to be valid
placeholder text, search, url, tel, email, password, number Text that appears in the form control when it has no value set
popovertarget button Designates an <input type="button"> as a control for a popover element
popovertargetaction button Specifies the action that a popover control should perform
readonly all except hidden, range, color, checkbox, radio, and buttons Boolean. The value is not editable
required all except hidden, range, color, and buttons Boolean. A value is required or must be checked for the form to be submittable
size text, search, url, tel, email, password Size of the control
src image Same as src attribute for <img>; address of image resource
step date, month, week, time, datetime-local, number, range Incremental values that are valid
type all Type of form control
value all except image The value of the control. When specified in the HTML, corresponds to the initial value
width image Same as width attribute for <img>

A few additional non-standard attributes are listed following the descriptions of the standard attributes.

Từ khóa » Html Textbox Tag