HTML formmethod Attribute

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 3 Examples
Forms & Input

What You’ll Learn

The formmethod attribute is a useful HTML feature that lets developers specify the HTTP method used when submitting a form. Applied to <button> or <input type="submit"> elements, it overrides the method on the parent <form> for that one submission.

01

Override method

Per-button HTTP verb.

02

GET

Data in URL params.

03

POST

Data in body.

04

Submit Buttons

button and input.

05

formMethod

JS property name.

06

Multi-Action

One form, two methods.

Purpose of formmethod

The formmethod attribute is designed to give developers control over the HTTP method used to submit a form on a per-button basis. This is particularly useful when you have multiple submit buttons in a form and want each to trigger a different type of request.

For example, a single form might offer “Preview” via GET (data visible in the URL for a read-only view) and “Save” via POST (data sent securely in the request body).

💡
GET vs POST at a glance

get appends name-value pairs to the URL—good for searches and idempotent reads. post sends data in the body—use for creating, updating, or sensitive data.

📝 Syntax

Add formmethod to a submit button with either get or post:

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

Syntax Rules

  • Valid on submit controls: <button type="submit">, <input type="submit">, and <input type="image">.
  • Accepted values: get and post (case-insensitive in HTML).
  • Overrides the parent form’s method only for that button’s submission.
  • Works with formaction and formenctype for full per-button submission control.

💎 Values

The formmethod attribute accepts the following values:

  • get — Submits form data as URL query parameters. Generally used for retrieving or filtering data. Bookmarkable and cacheable.
  • post — Submits form data in the HTTP request body. Commonly used for data that should not appear in the URL, such as passwords or large payloads.
formmethod-values.html
<!-- GET: /search?q=html -->
<button type="submit" formmethod="get">Search</button>

<!-- POST: data in request body -->
<button type="submit" formmethod="post">Save</button>

⚡ Quick Reference

ItemDetailsNotes
Attribute onSubmit buttonsNot on <form> itself
Valuesget, postCase-insensitive
GET behaviorData in URL query stringLimited length; visible in address bar
POST behaviorData in request bodyBetter for sensitive or large data
JS propertybutton.formMethodCamelCase in JavaScript
DefaultForm methodUsually get if omitted

Applicable Elements

ElementSupported?Notes
<button type="submit">YesSemantic submit buttons
<input type="submit">YesClassic submit inputs
<input type="image">YesImage-based submit control
<form>NoForms use method; buttons use formmethod
<input type="text">NoNot a submit control

Form method vs formmethod

AttributeOnBehavior
method<form>Default HTTP method for all submit buttons
formmethodSubmit button / inputOverrides method for that button only

GET vs POST

MethodData LocationBest For
getURL query stringSearch, filters, read-only previews
postRequest bodyLogin, create/update, file uploads

Examples Gallery

GET and POST buttons in one form, a preview-vs-save pattern, and dynamic formMethod with JavaScript.

👀 Live Preview

Two submit buttons in one form, each using a different HTTP method:

Implementation Example — GET and POST Buttons

Here’s a simple example demonstrating how to use the formmethod attribute in an HTML form:

index.html
<form action="/submit" method="post">
  <label for="data">Enter Data:</label>
  <input type="text" id="data" name="data">

  <button type="submit" formmethod="get">Submit with GET</button>
  <button type="submit" formmethod="post">Submit with POST</button>
</form>
Try It Yourself

How It Works

Clicking “Submit with GET” submits the form using the GET method. Clicking “Submit with POST” uses POST, regardless of the method="post" on the form tag (the GET button overrides it).

Example — Preview vs Save

A practical pattern: preview with GET, save with POST:

preview-save.html
<form action="/articles" method="post">
  <textarea name="body" required></textarea>

  <button type="submit" formmethod="get" formaction="/articles/preview">Preview</button>
  <button type="submit">Save</button>
</form>
Try It Yourself

How It Works

“Preview” sends a GET request to /articles/preview so the user can see a read-only view. “Save” uses the form’s default POST method to persist the article.

Dynamic Values with JavaScript

You can dynamically set the formmethod attribute using JavaScript to change the submission method based on user interaction:

index.html
<form action="/submit" method="post" id="dynamicForm">
  <label for="dynamicData">Enter Data:</label>
  <input type="text" id="dynamicData" name="dynamicData">

  <button type="button" onclick="setFormMethod('get')">Set Method to GET</button>
  <button type="button" onclick="setFormMethod('post')">Set Method to POST</button>
  <button type="submit" id="submitButton">Submit</button>
</form>

<script>
  function setFormMethod(method) {
    document.getElementById("submitButton").formMethod = method;
  }
</script>
Try It Yourself

How It Works

Clicking “Set Method to GET” assigns formMethod = "get" on the submit button. Clicking “Set Method to POST” sets it to post. The submit button then uses the dynamically chosen method.

♿ Accessibility

  • Label buttons clearly — When multiple submit buttons use different methods, names like “Preview” and “Save” must explain the outcome.
  • Warn about destructive POST actions — Users should understand which button changes data vs reads it.
  • Do not hide method differences — GET submissions expose data in the URL; make that clear if sensitive fields are involved.
  • Provide confirmation for irreversible actions — Even with correct method attributes, confirm deletes and major changes.

🧠 How formmethod Works

1

Form defines default method

Usually GET or POST on the form element.

Markup
2

Button may override with formmethod

Submit control picks GET or POST.

Override
3

Browser sends the request

Data goes in URL (GET) or body (POST).

Submit
=

Flexible submission behavior

One form, multiple HTTP methods without duplicating fields.

Browser Support

The formmethod attribute is supported in all modern browsers. It is part of the HTML5 form submission override attributes alongside formaction and formenctype.

HTML5 · Fully supported

Universal method override

All major browsers honor formmethod on submit controls.

99% Browser support
Google Chrome Fully supported
Full support
Mozilla Firefox Fully supported
Full support
Apple Safari Fully supported
Full support
Microsoft Edge Fully supported
Full support
formmethod attribute 99% supported

Bottom line: Use formmethod confidently; ensure your server handles both GET and POST if you offer both.

💡 Best Practices

✅ Do

  • Use formmethod to control submission methods for different buttons in the same form
  • Use GET for idempotent reads and POST for data changes
  • Ensure server-side handlers support both methods if you allow both
  • Pair with formaction when URL and method should both differ
  • Use formMethod (camelCase) in JavaScript

❌ Don’t

  • Send passwords or sensitive data via GET
  • Use GET for actions that modify server state
  • Put formmethod on non-submit controls
  • Assume users understand method differences without clear button labels
  • Rely on client-side method changes alone for security decisions

Conclusion

The formmethod attribute is a powerful tool for managing form submission behaviors in HTML. By using this attribute, you can specify different HTTP methods for form submissions on a per-button basis, enhancing the flexibility and functionality of your forms.

Dynamic control with JavaScript via formMethod adds further customization. Always label buttons clearly and handle both GET and POST correctly on the server.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about formmethod

Bookmark these before adding multi-method forms.

5
Core concepts
🔍 02

GET

Data in URL.

Value
📦 03

POST

Data in body.

Value
⚙️ 04

formMethod

JS property name.

Script
🔒 05

No secrets in GET

Use POST for sensitive data.

Security

❓ Frequently Asked Questions

It overrides the form’s method attribute for the submit button that was clicked, using GET or POST for that submission.
get and post. These are the only valid values for formmethod on submit controls.
<button type="submit">, <input type="submit">, and <input type="image">.
method is on the <form> as the default. formmethod on a submit button overrides it for that button only.
Use buttonElement.formMethod = "get" or setAttribute("formmethod", "post"). Note the camelCase property name in JavaScript.
Yes in all modern browsers. IE 10+ also supports formmethod on submit controls.

Master GET and POST in forms

Practice overriding HTTP methods with formmethod in the Try It editor.

Try GET vs POST example →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

3 people found this page helpful