HTML - <form> tag in HTML
The <form> tag in HTML is used to create an input form that collects user data and sends it to a server for processing.
Here are 6 common attributes of the <form> tag with examples:
-
action
Specifies the URL where the form data will be sent after submission.
Example:
<form action="/submit-form"> -
method
Specifies the HTTP method to use when sending form data. Common values are get and post.
Example:
<form method="post"> -
enctype
Specifies how the form data should be encoded when submitted.
Common values:
-
application/x-www-form-urlencoded (default)
-
multipart/form-data (used for file uploads)
Example:
<form enctype="multipart/form-data">
-
target
Specifies where to display the response after form submission.
Common values: _self, _blank, _parent, _top
Example:
<form target="_blank"> -
autocomplete
Enables or disables browser autocomplete for form fields.
Values: on or off
Example:
<form autocomplete="off"> -
novalidate
Tells the browser not to validate the form before submission.
Example:
<form novalidate>
Example combining attributes:
<form action="/submit" method="post" enctype="multipart/form-data" target="_self" autocomplete="on" novalidate>
<!-- form elements go here -->
</form>