HTML Form Attributes - Javatpoint
HTML Form Attributes - Javatpoint
HTML Form Attributes - Javatpoint
The action attribute of <form> element defines the process to be performed on form when form is submitted, or it is a URI to
process the form information.
The action attribute value defines the web page where information proceed. It can be .php, .jsp, .asp, etc. or any URL where
you want to process your form.
Note: If action attribute value is blank then form will be processed to the same page.
Example:
<label>User Name:</label><br>
<label>User Password</label><br>
<input type="submit">
</form>
Test it Now
Output:
https://www.javatpoint.com/html-form-attribute 1/9
4/19/2021 HTML Form Attributes - javatpoint
User Password
Submit
It will redirect to a new page "action.html" when you click on submit button
The method attribute defines the HTTP method which browser used to submit the form. The possible values of method attribute
can be:
post: We can use the post value of method attribute when we want to process the sensitive data as it does not display
the submitted data in URL.
Example:
get: The get value of method attribute is default value while submitting the form. But this is not secure as it displays
data in URL after submitting the form.
Example:
When submitting the data, it will display the entered data in the form of:
file:///D:/HTML/action.html?name=JavaTPoint&pass=123
The target attribute defines where to open the response after submitting the form. The following are the keywords used with
the target attribute.
_self: If we use _self as an attribute value, then the response will display in current page only.
Example:
_blank: If we use _blank as an attribute it will load the response in a new page.
https://www.javatpoint.com/html-form-attribute 2/9
4/19/2021 HTML Form Attributes - javatpoint
Example:
The HTML autocomplete attribute is a newly added attribute of HTML5 which enables an input field to complete automatically. It
can have two values "on" and "off" which enables autocomplete either ON or OFF. The default value of autocomplete attribute is
"on".
Example:
Example:
Note: it can be used with <form> element and <input> element both.
The HTML enctype attribute defines the encoding type of form-content while submitting the form to the server. The possible
values of enctype can be:
application/x-www-form-urlencoded: It is default encoding type if the enctype attribute is not included in the form.
All characters are encoded before submitting the form.
Example:
multipart/form-data: It does not encode any character. It is used when our form contains file-upload controls.
Example:
text/plain (HTML5): In this encoding type only space are encoded into + symbol and no any other special character
encoded.
Example:
https://www.javatpoint.com/html-form-attribute 3/9
4/19/2021 HTML Form Attributes - javatpoint
Example:
Test it Now
Output:
Enter age:
Enter email:
Submit
Try to change the form detials with novalidate atttribute and without novalidate attribute and see the difference.
Note: One should not omit the name attribute as when we submit the form the HTTP request includes both name-value pair and
if name is not available it will not process that input field.
Example:
</form>
Test it Now
Output:
https://www.javatpoint.com/html-form-attribute 4/9
4/19/2021 HTML Form Attributes - javatpoint
Enter age:
Enter email:
Submit
Note: If you will not use name attribute in any input field, then that input field will not be submitted, when
submit the form.
Click on submit and see the URL where email is not included in HTTP request as we have not used name attribute in the email
input field
The HTML value attribute defines the initial value or default value of an input field.
Example:
<form>
</form>
Test it Now
Output:
login
https://www.javatpoint.com/html-form-attribute 5/9
4/19/2021 HTML Form Attributes - javatpoint
Note: In password input filed the value attribute will always unclear
Example:
<form>
</form>
Test it Now
Output:
login
If you will try to submit the form without completing email field then it will give an error pop up.
The autofocus is a Boolean attribute which enables a field automatically focused when a webpage loads.
Example:
<form>
</form>
https://www.javatpoint.com/html-form-attribute 6/9
4/19/2021 HTML Form Attributes - javatpoint
The placeholder attribute can be used with text, password, email, and URL values.
When the user enters the value, the placeholder will be automatically removed.
Example:
<form>
</form>
Test it Now
Output:
Registration form
login
The disabled input filed does not receive click events, and these input value will not be sent to the server when submitting the
form.
Example:
Test it Now
https://www.javatpoint.com/html-form-attribute 7/9
4/19/2021 HTML Form Attributes - javatpoint
Output:
Registration form
login
The size attribute controls the size of the input field in typed characters.
Example:
<label>Account number</label><br>
<label>CVV</label><br>
Test it Now
Output:
Account number
CVV
login
https://www.javatpoint.com/html-form-attribute 8/9
4/19/2021 HTML Form Attributes - javatpoint
Example:
Test it Now
Output:
User Name:
User password:
The email field is outside the form but still it will remain part of the form
User email:
Submit
https://www.javatpoint.com/html-form-attribute 9/9