HTML Form Attributes
HTML Form Attributes
HTML form attributes control how a form behaves when it is submitted and how the browser processes the form data.
The action Attribute
The action attribute defines where the form data is sent when the form is submitted. This is usually a server-side file that processes the input.
<form action="/action_page.php"> <label for="fname">First name:</label><br> <input type="text" id="fname" name="fname" value="John"><br> <label for="lname">Last name:</label><br> <input type="text" id="lname" name="lname" value="Doe"><br><br> <input type="submit" value="Submit"> </form>
If the action attribute is omitted, the form data is submitted to the current page.
The target Attribute
The target attribute specifies where the response will be displayed after the form is submitted.
_self– opens in the same window (default)_blank– opens in a new tab or window_parent– opens in the parent frame_top– opens in the full browser windowframename– opens in a named iframe
<form action="/action_page.php" target="_blank">
The method Attribute
The method attribute specifies how form data is sent to the server.
GET Method
With method="get", form data is appended to the URL as name/value pairs.
<form action="/action_page.php" method="get">
- Form data is visible in the URL
- URL length is limited
- Can be bookmarked
- Not suitable for sensitive data
POST Method
With method="post", form data is sent inside the HTTP request body.
<form action="/action_page.php" method="post">
- Form data is not visible in the URL
- No size limitation
- Cannot be bookmarked
- Recommended for sensitive or personal data
The autocomplete Attribute
The autocomplete attribute controls whether the browser should automatically fill in form values based on previous input.
<form action="/action_page.php" autocomplete="on">
Use autocomplete="off" to disable this behavior.
The novalidate Attribute
The novalidate attribute disables built-in browser validation when the form is submitted.
<form action="/action_page.php" novalidate>
List of <form> Attributes
accept-charset– character encodings for form submissionaction– destination URL for submitted dataautocomplete– enables or disables autocompleteenctype– encoding type for submitted data (POST only)method– HTTP method used to send dataname– name of the formnovalidate– disables form validationrel– relationship between linked resourcestarget– where to display the response