HTML Input Attributes
HTML Input Attributes
w3schools.com
THE WORLD'S LARGEST WEB DEVELOPER SITE
☰ HTML
Example
<form action="">
First name:<br>
<input type="text" name="firstname" value="John">
<br>
Last name:<br>
<input type="text" name="lastname">
</form>
Try it Yourself »
Example
<form action="">
First name:<br>
<input type="text" name="firstname" value="John" readonly>
<br>
Last name:<br>
http://www.w3schools.com/html/html_form_attributes.asp 1/13
28/06/2016 HTML Input Attributes
Try it Yourself »
The readonly attribute does not need a value. It is the same as writing
readonly="readonly".
Example
<form action="">
First name:<br>
<input type="text" name="firstname" value="John" disabled>
<br>
Last name:<br>
<input type="text" name="lastname">
</form>
Try it Yourself »
The disabled attribute does not need a value. It is the same as writing disabled="disabled".
Example
<form action="">
First name:<br>
<input type="text" name="firstname" value="John" size="40">
http://www.w3schools.com/html/html_form_attributes.asp 2/13
28/06/2016 HTML Input Attributes
<br>
Last name:<br>
<input type="text" name="lastname">
</form>
Try it Yourself »
Example
<form action="">
First name:<br>
<input type="text" name="firstname" maxlength="10">
<br>
Last name:<br>
<input type="text" name="lastname">
</form>
Try it Yourself »
With a maxlength attribute, the input control will not accept more than the allowed number
of characters.
The attribute does not provide any feedback. If you want to alert the user, you must write
JavaScript code.
Input restrictions are not foolproof. JavaScript provides many ways to add illegal
input.
To safely restrict input, restrictions must be checked by the receiver (the server) as
well.
HTML5 Attributes
HTML5 added the following attributes for <input>:
autocomplete
autofocus
http://www.w3schools.com/html/html_form_attributes.asp 3/13
28/06/2016 HTML Input Attributes
form
formaction
formenctype
formmethod
formnovalidate
formtarget
height and width
list
min and max
multiple
pattern (regexp)
placeholder
required
step
autocomplete
novalidate
When autocomplete is on, the browser automatically complete values based on values that
the user has entered before.
Tip: It is possible to have autocomplete "on" for the form, and "off" for specific input fields,
or vice versa.
The autocomplete attribute works with <form> and the following <input> types: text,
search, url, tel, email, password, datepickers, range, and color.
Example
An HTML form with autocomplete on (and off for one input field):
http://www.w3schools.com/html/html_form_attributes.asp 4/13
28/06/2016 HTML Input Attributes
Try it Yourself »
Tip: In some browsers you may need to activate the autocomplete function for this to
work.
When present, novalidate specifies that form data should not be validated when submitted.
Example
Indicates that the form is not to be validated on submit:
Try it Yourself »
When present, it specifies that an <input> element should automatically get focus when
the page loads.
Example
Let the "First name" input field automatically get focus when the page loads:
Try it Yourself »
http://www.w3schools.com/html/html_form_attributes.asp 5/13
28/06/2016 HTML Input Attributes
Tip: To refer to more than one form, use a spaceseparated list of form ids.
Example
An input field located outside the HTML form (but still a part of the form):
Try it Yourself »
The formaction attribute overrides the action attribute of the <form> element.
Example
An HTML form with two submit buttons, with different actions:
<form action="action_page.php">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit"><br>
<input type="submit" formaction="demo_admin.asp"
value="Submit as admin">
</form>
Try it Yourself »
http://www.w3schools.com/html/html_form_attributes.asp 6/13
28/06/2016 HTML Input Attributes
The formenctype attribute overrides the enctype attribute of the <form> element.
Example
Send formdata that is default encoded (the first submit button), and encoded as
"multipart/formdata" (the second submit button):
Try it Yourself »
The formmethod attribute overrides the method attribute of the <form> element.
Example
The second submit button overrides the HTTP method of the form:
</form>
Try it Yourself »
When present, it specifies that the <input> element should not be validated when
submitted.
The formnovalidate attribute overrides the novalidate attribute of the <form> element.
Example
A form with two submit buttons (with and without validation):
<form action="action_page.php">
E‐mail: <input type="email" name="userid"><br>
<input type="submit" value="Submit"><br>
<input type="submit" formnovalidate value="Submit without
validation">
</form>
Try it Yourself »
The formtarget attribute overrides the target attribute of the <form> element.
Example
A form with two submit buttons, with different target windows:
http://www.w3schools.com/html/html_form_attributes.asp 8/13
28/06/2016 HTML Input Attributes
<form action="action_page.php">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit as normal">
<input type="submit" formtarget="_blank"
value="Submit to a new window">
</form>
Try it Yourself »
The height and width attributes are only used with <input type="image">.
Always specify the size of images. If the browser does not know the size, the page
will flicker while images load.
Example
Define an image as the submit button, with height and width attributes:
Try it Yourself »
Example
An <input> element with predefined values in a <datalist>:
<input list="browsers">
http://www.w3schools.com/html/html_form_attributes.asp 9/13
28/06/2016 HTML Input Attributes
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
Try it Yourself »
The min and max attributes work with the following input types: number, range, date,
datetime, datetimelocal, month, time and week.
Example
<input> elements with min and max values:
Try it Yourself »
When present, it specifies that the user is allowed to enter more than one value in the
<input> element.
The multiple attribute works with the following input types: email, and file.
http://www.w3schools.com/html/html_form_attributes.asp 10/13
28/06/2016 HTML Input Attributes
Example
A file upload field that accepts multiple values:
Try it Yourself »
The pattern attribute works with the following input types: text, search, url, tel, email, and
password.
Tip: Use the global title attribute to describe the pattern to help the user.
Example
An input field that can contain only three letters (no numbers or special characters):
Try it Yourself »
The hint is displayed in the input field before the user enters a value.
The placeholder attribute works with the following input types: text, search, url, tel, email,
and password.
http://www.w3schools.com/html/html_form_attributes.asp 11/13
28/06/2016 HTML Input Attributes
Example
An input field with a placeholder text:
Try it Yourself »
When present, it specifies that an input field must be filled out before submitting the form.
The required attribute works with the following input types: text, search, url, tel, email,
password, date pickers, number, checkbox, radio, and file.
Example
A required input field:
Try it Yourself »
Tip: The step attribute can be used together with the max and min attributes to create a
range of legal values.
The step attribute works with the following input types: number, range, date, datetime,
datetimelocal, month, time and week.
Example
An input field with a specified legal number intervals:
http://www.w3schools.com/html/html_form_attributes.asp 12/13
28/06/2016 HTML Input Attributes
Try it Yourself »
http://www.w3schools.com/html/html_form_attributes.asp 13/13