HTML method Attribute

Description

The HTML method attribute specifies how to send form data to a server. It is used within a <form> element to define the HTTP method for sending data to the action URL. The method attribute can take two values:

  • GET: This method appends the form data to the action URL with a question mark (?). The data is visible in the URL, making it unsuitable for sensitive information. It is ideal for form submissions where the user wants to bookmark or share the URL. GET requests can be cached and remain in the browser history.

  • POST: This method sends the form data as an HTTP post transaction. Form data sent via POST method will not be visible in the URL, making it a more secure way of transmitting sensitive information. POST requests do not remain in the browser history, cannot be bookmarked, and have no restrictions on data length.

The choice between GET and POST methods depends on the application's requirements, including the need for security, data size, and whether or not the submission result should be bookmarkable.

Syntax

<form method="GET | POST">

Values

  • GETThe default value. It sends data using URL name/value pairs which is visible. Therefore, GET should not be used when handling sensitive data (e.g. passwords, bank information).
  • POSTSends data using an HTTP post transaction with data in the request body, which is invisible. The POST method is more secure.

Applies To

The method attribute can be used on the following html elements.

Example

<form action="formscript.php" method="get">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="firstname" placeholder="Your name..">
<br><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lastname" placeholder="Your last name..">
<br><br>
<input type="submit" value="Submit">
</form>

Browser Support

The following table will show you the current browser support for the HTML method Attribute.

Desktop
Edge Chrome Firefox Opera Safari
1211153
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview
18414214.4

Last updated by CSSPortal on: 28th March 2024