Open In App

How to set the Method Attribute for the Form Submission in HTML ?

Last Updated : 21 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The method of form submission in HTML is set using the “method” attribute within the <form> tag. The “method” attribute specifies the HTTP method used when submitting form data to the server. There are two commonly used methods: “GET” and “POST”.

Syntax

<form method="GET/POST" action="URL">
<!-- Form fields -->
</form>

The table below illustrates the HTTP Methods alongside their descriptions.

HTTP Method Description
GET Sends form data as part of the URL query string. Suitable for submitting small amounts of data or retrieving data from the server.
POST Sends form data in the body of the HTTP request. Suitable for submitting large amounts of data or sensitive information securely.

Methods

  • GET Method: Use when the form data does not contain sensitive information and when you want to retrieve data from the server. It appends the form data to the URL as key-value pairs.

Syntax

<form method="GET" action="submit.php">
<!-- Form fields -->
</form>
  • POST Method: Recommended for submitting sensitive data or large amounts of data. It sends form data in the body of the HTTP request.

Syntax

<form method="POST" action="submit.php">
<!-- Form fields -->
</form>

Note: The choice between “GET” and “POST” depends on the nature of the data being submitted and the desired behavior of the form. Use “GET” for simple queries or retrieving data and “POST” for submitting data that may contain sensitive or large information.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads