Open In App

HTML method Attribute

Last Updated : 29 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

The HTML method Attribute is used to specify the HTTP method used to send data while submitting the form. There are two kinds of HTTP Methods, which are GET and POST. The method attribute can be used with the <form> element. 

Attribute Values: 

  • GET: It is the default value. In the GET method, after the submission of the form, the form values will be visible in the address bar of the new browser tab. It has a limited size of about 3000 characters. It is only useful for non-secure data not for sensitive information.
  • POST: In the post method, after the submission of the form, the form values will not be visible in the address bar of the new browser tab as it was visible in the GET method. It appends form data inside the body of the HTTP request. It has no size limitation. This method does not support bookmark the result. 

Syntax: 

<form method="get|post">

Example: This Example illustrates the use of method attribute. 

<!DOCTYPE html>
<html>
<body style="text-align:center;">
    <h1 style="color:green;"> 
    GeeksForGeeks 
    </h1>
    <h2>HTML  method Attribute</h2>
    <form id="users"
          action="#"
          method="GET" 
          target="_blank">
        First name:
        <input type="text" 
               name="fname"
               value="Manas">
        <br> Last name:
        <input type="text"
               name="lname"
               value="Chhabra">
        <br>
        <input type="submit"
               value="Submit">
    </form>
    
<p>
      After submitting the form, 
      input values are shown in the address 
      bar of the window.
      </p>

</body>
</html>

Output: 

Supported Browsers: The browser supported by HTML Method Attribute are listed below: 

HTML method Attribute – FAQs

What is the difference between method=”GET” and method=”POST”?

GET sends data appended to the URL, making it visible in the address bar, suitable for simple queries. POST sends data in the request body, making it more secure and suitable for sensitive information or larger data.

When should you use method=”GET”?

Use method=”GET” when the form submission is idempotent (doesn’t change server state), like search queries or filtering. It’s also suitable when data is non-sensitive and minimal.

When should you use method=”POST”?

Use method=”POST” for forms that change server state (like submitting data to a database), or when transmitting sensitive information (like passwords) or large amounts of data.

What happens if the method attribute is omitted?

If the method attribute is omitted, the default method is GET.

Can you use other HTTP methods like PUT or DELETE with the method attribute?

No, the method attribute only supports GET and POST. However, other methods like PUT or DELETE can be specified using JavaScript or other backend configurations.


Next Article

Similar Reads

three90RightbarBannerImg