HTML formmethod Attribute

The HTML formmethod attribute specifies the HTTP method used when a particular submit button submits its associated form. It overrides the method attribute of the <form> element for that submission.

Syntax

The formmethod attribute is placed on a submit button and specifies the method used when that button submits its associated form.

<button type="submit" formmethod="post">Submit</button>

It can also be used with an <input> element that acts as a submit button.

<input type="submit" value="Submit" formmethod="get">

Elements That Use the formmethod Attribute

The formmethod attribute applies to elements that act as submit buttons.

Element Description
<button> Specifies an alternate submission method when the element acts as a submit button.
<input type="submit"> Specifies an alternate submission method for a submit input.
<input type="image"> Specifies an alternate submission method for an image submit button.

Attribute Values

The formmethod attribute supports methods used for form submission.

Value Description
get Appends the submitted form data to the destination URL as a query string.
post Sends the submitted form data in the request body.
dialog Closes the associated dialog when the form is contained in a <dialog>, without submitting the form data to a server.

Overriding the Form method

A form normally uses the submission method specified by its method attribute. When the activated submit button has a formmethod attribute, the button's method is used instead.

<form action="result.php" method="post">
  <input type="text" name="search">
  <button type="submit">Submit with POST</button>
  <button type="submit" formmethod="get">Submit with GET</button>
</form>

The first button uses the form's post method. The second button overrides it and submits the form using get.

GET and POST

With get, the submitted form data is added to the URL as a query string. This makes GET useful for requests such as searches where the resulting URL can be bookmarked or shared.

With post, the form data is sent in the request body instead of being appended to the URL. POST is commonly used when submitting data that changes server-side information or when the submitted data should not become part of the URL.

Using POST does not encrypt form data. HTTPS should be used when information needs to be protected while it travels between the browser and server.

The dialog Value

The dialog value is used with a form inside a <dialog> element. Instead of sending the form data to a server, submitting the form closes the dialog.

<dialog open>
  <form>
    <button type="submit" formmethod="dialog">Close</button>
  </form>
</dialog>

This provides a way for an individual submit button to close the dialog without changing the form's normal submission method.

The formmethod attribute belongs to a group of submit-button attributes that can override submission settings defined by the associated form.

Submit Button Attribute Form Attribute Overridden
formaction action
formenctype enctype
formmethod method
formnovalidate novalidate
formtarget target

Common Mistakes

Do not confuse formmethod with the form's method attribute. The method attribute establishes the form's normal submission method, while formmethod overrides it for an individual submit button.

Do not use formmethod on ordinary controls that cannot submit a form. For <input>, it applies to the submit and image states.

Do not assume POST provides encryption. Use HTTPS when submitted information needs protection during transmission.

Browser Support

Baseline: Widely available indicates a feature has been supported by core browsers for at least 30 months. At this stage, the feature is considered stable and safe for most websites to use without needing to worry about compatibility issues or fallbacks, as it is supported by the vast majority of users' devices and browser versions.

The formmethod attribute is widely supported on submit-capable <button> and <input> elements in current core browsers.

Checking Browser Support

For current browser compatibility information, visit Can I Use? . Search for the HTML element or attribute you want to check. You can also narrow your search by entering an element name and attribute name separated by a colon. Search results can include related HTML features, element attributes, input types, APIs, and other technologies, so select the result that most closely matches the feature you are checking.

Try the formmethod Attribute

The example uses a form with method="post" and two submit buttons. The first uses POST, while the second uses formmethod="get" to override the form's submission method.

Play in Editor

Summary

The HTML formmethod attribute specifies the submission method used when a particular submit button submits its associated form. It can override the form's method attribute with get, post, or dialog, allowing individual submit buttons to use different submission behavior.