HTML Form Attributes

Form attributes define how and where form data is sent, such as the submission URL, HTTP method, and target behavior. They control the overall behavior of the form during submission.

On this page

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 window
  • framename – 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 submission
  • action – destination URL for submitted data
  • autocomplete – enables or disables autocomplete
  • enctype – encoding type for submitted data (POST only)
  • method – HTTP method used to send data
  • name – name of the form
  • novalidate – disables form validation
  • rel – relationship between linked resources
  • target – where to display the response

HTML Form Attributes Examples (6)