👀 Live Preview
Toggle between GET and POST to see where data would be sent:
Click a button to preview submission.

The method attribute on <form> tells the browser how to send form data to the server when the user submits. It accepts two HTTP methods: get (the default) and post. With get, named fields are appended to the URL as a query string—ideal for searches. With post, data travels in the request body—better for logins, registrations, and changes that should not appear in the address bar. Always pair method with the action attribute, which sets the destination URL.
get or post.
Form element.
Query string.
Hidden from URL.
Button override.
Change at runtime.
method AttributeThe primary purpose of method is to define how the browser packages and delivers form field values to the URL in action. A search box with method="get" produces bookmarkable URLs like /search?q=html. A signup form with method="post" keeps names and emails out of the visible URL and avoids length limits that affect long query strings.
Servers use the HTTP method to decide how to handle the request. GET requests should be safe and idempotent (read data without side effects). POST is used when submitting data that creates or updates something. HTML forms only expose get and post—other verbs like PUT or DELETE require JavaScript APIs or server configuration.
POST keeps data out of the URL bar, but the request can still be intercepted without HTTPS. Always use HTTPS in production and validate every field on the server. Never rely on method="post" alone for security.
Add method on a <form> together with action:
<!-- POST: data in request body -->
<form action="/submit-form" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<label for="email">Email:</label>
<input type="email" id="email" name="email">
<button type="submit">Submit</button>
</form>
<!-- GET: data in URL query string (default if method omitted) -->
<form action="/search" method="get">
<input type="search" name="q">
<button type="submit">Search</button>
</form><form> elements.get or post (case-insensitive in HTML).get when the attribute is omitted.action (URL) and named name attributes on controls.type="file" require method="post" and enctype="multipart/form-data".formElement.method = "post".The method attribute accepts two HTTP methods for HTML forms:
get — Default. Appends name=value pairs to the action URL after ?. Suitable for searches, filters, and read-only queries. URLs can be bookmarked and shared.post — Sends data in the HTTP request body (typically application/x-www-form-urlencoded or multipart/form-data). Use for login, registration, checkout, and any operation that changes server data.document.getElementById("dynamicForm").method = "post";
document.getElementById("searchForm").setAttribute("method", "get");| Use case | Markup | Notes |
|---|---|---|
| Search box | <form method="get" action="/search"> | Query in URL |
| Login / signup | <form method="post" action="/login"> | Data in body |
| Default behavior | Omit method (same as get) | GET is implicit |
| File upload | method="post" enctype="multipart/form-data" | Required for files |
| Button override | <button formmethod="post"> | Per-button method |
| JS update | form.method = "post" | Runtime switch |
| Element | Supported? | Notes |
|---|---|---|
<form> | Yes | Primary and only standard element |
<button> / <input type="submit"> | No (method) | Use formmethod to override |
<input>, <a>, <div> | No | Not valid on these elements |
get vs post vs formmethod| Topic | GET | POST |
|---|---|---|
| Where data goes | URL query string | Request body |
| Visible in address bar | Yes | No (fields not in URL) |
| Bookmarkable | Yes | No |
| Typical use | Search, filters | Login, create, update |
| Length limits | URL length varies by browser | Much larger payloads |
formmethod on a submit button overrides the form’s method for that single submission only.
POST signup form, GET search form, and switching form.method with JavaScript.
Toggle between GET and POST to see where data would be sent:
Click a button to preview submission.
Send registration data in the request body:
<form action="/submit-form" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<label for="email">Email:</label>
<input type="email" id="email" name="email">
<button type="submit">Submit</button>
</form>Only controls with a name attribute are submitted. POST is the standard choice for forms that create accounts or change data.
Put the search term in the URL for bookmarkable results:
<form action="/search" method="get">
<label for="q">Search:</label>
<input type="search" id="q" name="q">
<button type="submit">Search</button>
</form>GET is the default when method is omitted. Avoid GET for passwords or actions that modify server state.
Change the submission method when application logic requires it:
<form id="dynamicForm" action="/api" method="get">
<input type="text" name="topic">
</form>
<script>
document.getElementById("dynamicForm").method = "post";
</script>The old reference set method = "post" in code but described get in the explanation—always keep code and text aligned. Prefer setting the correct method in HTML unless you truly need runtime switching.
for and id.aria-labelledby so assistive tech users know what the form does before submitting.type="submit" controls, not divs with click handlers only.get or post on form.
Named fields collected.
URL query or body.
Processed per method.
The method attribute on <form> with values get and post is fully supported in all browsers since the earliest HTML forms. Behavior is consistent across Chrome, Firefox, Safari, and Edge.
Every browser honors get and post on forms.
Bottom line: Core HTML feature; safe to use in every production form.
get for searches and read-only filterspost for login, signup, and data changesaction to a meaningful server URLmethod="get"method with formmethod on buttonsname attributes on fields you need submittedThe method attribute is a foundation of HTML forms. It chooses between get and post, determining whether data appears in the URL or travels in the request body. Pick the method that matches how the server should treat the submission.
Use GET for bookmarkable searches, POST for sensitive or state-changing operations, HTTPS everywhere in production, and server-side validation always. Update form.method in JavaScript only when your workflow truly requires it.
methodBookmark these before building forms.
Only two values.
ValuesForm element.
ScopeQuery string.
GETNot in address bar.
POSTReal security.
Securityget or post) used when the form is submitted to the action URL.<form> element. Submit buttons use formmethod to override the form default for one submission.formElement.method = "post" or setAttribute("method", "post").get. If you omit the attribute, the form behaves as method="get".Practice POST signup forms, GET search, and dynamic form.method in the Try It editor.
5 people found this page helpful