Open In App

HTML <form> method Attribute

Improve
Improve
Like Article
Like
Save
Share
Report

The HTML <form> 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. 

Syntax: 

<form method="get | post">

Attribute Values: 

Attribute Values

Description

GET

Form values are visible in the address bar, limited to 3000 characters, suitable for non-sensitive data.

POST

Form values not visible in the address bar, have no size limit, are secure for sensitive data, not bookmarkable

Supported Tags: 

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

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML form method Attribute
    </title>
</head>
 
<body style="text-align:center;">
 
    <h1 style="color:green;">GeeksforGeeks</h1>
    <h3> HTML <form> Method Attribute. </h3>
 
    <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>
    <p>
        By clicking the submit button the Entered<br>
        details will be sent to "/action_page.php"
    </p>
</body>
 
</html>


Output: 
 

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

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML form method Attribute
    </title>
</head>
 
<body style="text-align:center;">
 
    <h1 style="color:green;">GeeksforGeeks</h1>
 
    <h3>HTML <form> Method Attribute.</h3>
 
    <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>
    <p>
        By clicking the login button the Entered<br>
        details will be sent to "/action_page.php"
    </p>
</body>
 
</html>


Output: 
 

Supported Browsers: 

  • Google Chrome 1
  • Edge 12
  • Mozilla Firefox 1
  • Safari 15
  • Opera 4


Last Updated : 18 Jan, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads