CSS Portal

HTML method Attribute

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

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

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 information will show you the current browser support for the HTML method attribute. Hover over a browser icon to see the version that first introduced support for this HTML attribute.

This attribute is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 28th March 2024

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!