HTML <form> method Attribute

Last Updated : 23 May, 2026

The method attribute in the <form> tag specifies how form data is sent to the server. It mainly defines whether the data is submitted using the GET or POST method.

  • Defines the HTTP method used for form submission.
  • Common values are GET and POST.
  • GET appends data to the URL, while POST sends data securely in the request body.

Syntax: 

<form method="post">
<!-- form elements -->
</form>
  • GET: Sends form data through the URL, suitable for non-sensitive data and limited in size.
  • POST: Sends form data in the request body, more secure, and suitable for large or sensitive data.

Example 1: Illustrates the use of GET method attribute with an example. 

html
<!--Driver Code Starts-->
<!DOCTYPE html>
<html>

<head>
    <title>
        HTML form method Attribute
    </title>
</head>

<body style="text-align:center;">

    <h1 style="color:green;">GeeksforGeeks</h1>
    <h3> HTML &lt;form&gt; Method Attribute. </h3>

<!--Driver Code Ends-->

    <form action="/action_page.php" id="users" 
          action="#" method="GET" target="_blank">

        First name: <input type="text" name="fname" 
                           placeholder="Enter first name">
        <br><br>
        Last name: <input type="text" name="lname" 
                          placeholder="Enter last name">
        <br><br>
        <input type="submit" value="Submit">
    </form>

<!--Driver Code Starts-->
    <p>
        By clicking the submit button<br>
        Entered details will be sent to "/action_page.php"
    </p>
</body>

</html>
<!--Driver Code Ends-->

Example 2: Illustrates the use of the POST method attribute. This method sends the form-data as an HTTP post-transaction. 

html
<!--Driver Code Starts-->
<!DOCTYPE html>
<html>

<head>
    <title>
        HTML form method Attribute
    </title>
</head>

<body style="text-align:center;">

    <h1 style="color:green;">GeeksforGeeks</h1>

    <h3>HTML &lt;form&gt; Method Attribute.</h3>

<!--Driver Code Ends-->

    <form action="/action_page.php" id="users" 
          action="#" method="POST" target="_blank">
        Email_id: <input type="text" name="Email_id" 
                         placeholder="Enter email_id">
        <br><br>
        Password: <input type="password" 
                         placeholder="Enter Password">
        Confirm Password: <input type="password" 
                                 placeholder="Re-enter Password">
        <br><br>
        <input type="button" value="login">
    </form>

<!--Driver Code Starts-->
    <p>
        By clicking the login button<br>
        Entered details will be sent to "/action_page.php"
    </p>
</body>

</html>
<!--Driver Code Ends-->
Comment