HTML method Attribute

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The method attribute on a <form> sets how the browser submits the form. Allowed values (case-insensitive) are get (default), post, and dialog. Pair it with action (the URL that handles the submit) and, for file uploads with POST, enctype.

A submit control can override the form for one click with formmethod. Use get for safe searches, post when data changes or must stay out of the URL, and dialog to close a parent <dialog> without a normal HTTP request.

Baseline · Widely available.

Not deprecated and not experimental. get and post are long-supported. dialog needs a supporting <dialog> (widely available in modern browsers).

POST is not encryption.

POST keeps fields out of the address bar, but data is still plain on the wire without HTTPS. Always use HTTPS for passwords and personal data.

HTML Syntax

syntax.html
<form action="…" method=" get | post | dialog">

If method is omitted, the browser uses get. With method="dialog", action is ignored.

Attribute Values

Three allowed values:

ValueDescriptionTry it
getDefault. Appends fields to the action URL as a query string (?name=value)Try it
postSends form data in the HTTP request body. Use for logins, writes, and file uploadsTry it
dialogInside a <dialog>, closes the dialog on submit without sending data to a URLTry it

Live Preview

Change method, then submit. Navigation is blocked so you can read what the browser would do.

Demo form only — submit shows the planned request instead of leaving the page.

Form

method="get" — fields go in the URL query string

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — GET Search Form

Use get when the submit is a safe, bookmarkable query.

HTML
<form action="/search" method="get">
  <label for="q">Search:</label>
  <input type="search" id="q" name="q">
  <button type="submit">Go</button>
</form>
Try It Yourself

How It Works

  1. method="get" (or omit it) tells the browser to use HTTP GET.
  2. Named fields become query parameters on the action URL.
  3. Visible in the address bar — good for searches, bad for passwords.
  4. Idempotent use. Prefer GET when submit only reads data.

Example 2 — POST Login Form

Use post when values should travel in the request body.

HTML
<form action="/login" method="post">
  <label for="email">Email:</label>
  <input type="email" id="email" name="email" required>

  <label for="password">Password:</label>
  <input type="password" id="password" name="password" required>

  <button type="submit">Log in</button>
</form>
Try It Yourself

How It Works

  1. method="post" puts the payload in the HTTP body.
  2. Default encoding is application/x-www-form-urlencoded (see enctype).
  3. Better for secrets than GET — values are not shown in the URL or browser history the same way.
  4. Still validate server-side and serve the form over HTTPS.

Example 3 — Close a Dialog with method="dialog"

Inside <dialog>, submit closes the dialog instead of posting to a URL.

HTML
<dialog id="confirm" open>
  <p>Save your changes?</p>
  <form method="dialog">
    <button value="cancel">Cancel</button>
    <button value="ok">OK</button>
  </form>
</dialog>
Try It Yourself

How It Works

  1. Nest the form inside <dialog>.
  2. method="dialog" closes the dialog on submit; action is ignored.
  3. Button value can become the dialog’s returnValue.
  4. No HTTP trip. Use this for confirm/cancel UI, not for saving to a server.

Edge Cases & Pitfalls

Most mistakes come from treating POST as “secure” or putting secrets in GET URLs.

security

Never put passwords in GET

Query strings land in history, logs, and Referer headers. Use post plus HTTPS for credentials.

default

Omitted method means get

If you forget method, the form still submits — as GET. Set post explicitly when you need a body.

override

formmethod can override

A button’s formmethod wins for that submit. Check both the form and the button.

files

File uploads need POST + multipart

Use method="post" with enctype="multipart/form-data" for type="file".

dialog

dialog is not a server method

It closes a <dialog> and skips the HTTP submit. Do not use it when the server must receive the data.

Browser Support

method is an HTML attribute on form elements in the browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

method

get and post are supported everywhere modern browsers run. method="dialog" works with the HTML dialog element in current Chrome, Firefox, Safari, and Edge.

97% Global support (approx.)
Google Chrome get/post: all · dialog: 37+
Full support
Mozilla Firefox get/post: all · dialog: 98+
Full support
Apple Safari get/post: all · dialog: 15.4+
Full support
Microsoft Edge get/post: all · dialog: 79+
Full support
Opera get/post: all · dialog: modern
Full support
Samsung Internet Modern
Full support
Internet Explorer get/post: yes · dialog: no
Partial
method Widely supported

Bottom line: Safe to use get and post everywhere. Use method="dialog" when you target browsers that support the dialog element.

Key Takeaways

  • Role: choose get, post, or dialog for form submit behavior.
  • Default: omitted method means get.
  • GET vs POST: query string for reads; request body for writes and secrets.
  • Security: POST needs HTTPS; it is not encryption by itself.

One line: method decides whether form data goes in the URL, the request body, or closes a dialog.

Frequently Asked Questions

On a form element, method chooses how the browser submits data: get (query string, default), post (request body), or dialog (close a parent dialog without a normal HTTP submit).
GET appends named fields to the action URL after ?. POST sends data in the HTTP request body. Use GET for safe searches; use POST for login, uploads, and anything that changes data.
Only the form element. A submit button can override it with formmethod for that click only.
No. POST hides values from the address bar but does not encrypt them. Use HTTPS and validate input on the server.
When the form is inside a dialog, submitting it closes the dialog, fires submit, and does not send data to an action URL. The action attribute is ignored in that case.
If you omit method, the browser uses get.

Next: min

Set a lower bound on number, date, and range inputs.

min tutorial →

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.

10 people found this page helpful