HTML method Attribute

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

Introduction

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.

What You’ll Learn

01

HTTP method

get or post.

02

<form> only

Form element.

03

Default get

Query string.

04

POST body

Hidden from URL.

05

vs formmethod

Button override.

06

.method JS

Change at runtime.

Purpose of method Attribute

The 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 is not encryption

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.

📝 Syntax

Add method on a <form> together with action:

method.html
<!-- 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>

Syntax Rules

  • Valid only on <form> elements.
  • Allowed values: get or post (case-insensitive in HTML).
  • Default is get when the attribute is omitted.
  • Works with action (URL) and named name attributes on controls.
  • File uploads with type="file" require method="post" and enctype="multipart/form-data".
  • JavaScript IDL property: formElement.method = "post".

💎 Values

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.
method-js.html
document.getElementById("dynamicForm").method = "post";

document.getElementById("searchForm").setAttribute("method", "get");

⚡ Quick Reference

Use caseMarkupNotes
Search box<form method="get" action="/search">Query in URL
Login / signup<form method="post" action="/login">Data in body
Default behaviorOmit method (same as get)GET is implicit
File uploadmethod="post" enctype="multipart/form-data"Required for files
Button override<button formmethod="post">Per-button method
JS updateform.method = "post"Runtime switch

Applicable Elements

ElementSupported?Notes
<form>YesPrimary and only standard element
<button> / <input type="submit">No (method)Use formmethod to override
<input>, <a>, <div>NoNot valid on these elements

get vs post vs formmethod

TopicGETPOST
Where data goesURL query stringRequest body
Visible in address barYesNo (fields not in URL)
BookmarkableYesNo
Typical useSearch, filtersLogin, create, update
Length limitsURL length varies by browserMuch larger payloads

formmethod on a submit button overrides the form’s method for that single submission only.

Examples Gallery

POST signup form, GET search form, and switching form.method with JavaScript.

👀 Live Preview

Toggle between GET and POST to see where data would be sent:

Click a button to preview submission.

Example — POST Form

Send registration data in the request body:

post-form.html
<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>
Try It Yourself

How It Works

Only controls with a name attribute are submitted. POST is the standard choice for forms that create accounts or change data.

Example — GET Search Form

Put the search term in the URL for bookmarkable results:

get-search.html
<form action="/search" method="get">

  <label for="q">Search:</label>

  <input type="search" id="q" name="q">

  <button type="submit">Search</button>

</form>
Try It Yourself

How It Works

GET is the default when method is omitted. Avoid GET for passwords or actions that modify server state.

Dynamic Values with JavaScript

Change the submission method when application logic requires it:

dynamic-method.html
<form id="dynamicForm" action="/api" method="get">

  <input type="text" name="topic">

</form>



<script>

  document.getElementById("dynamicForm").method = "post";

</script>
Try It Yourself

How It Works

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.

♿ Accessibility

  • Label every control — Whether GET or POST, users need clear labels tied with for and id.
  • Announce form purpose — Use a heading or aria-labelledby so assistive tech users know what the form does before submitting.
  • Do not put secrets in GET URLs — Passwords in query strings appear in browser history, logs, and referrer headers.
  • Provide submit feedback — After POST, redirect or update the page so users know the submission succeeded.
  • Keyboard accessible — Ensure submit buttons are real type="submit" controls, not divs with click handlers only.

🧠 How method Works

1

Author sets method

get or post on form.

Markup
2

User submits

Named fields collected.

Submit
3

Browser sends HTTP

URL query or body.

Request
=

Server receives data

Processed per method.

Browser Support

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.

HTML4+ · Fully supported

Universal form submission

Every browser honors get and post on forms.

100% 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
method get and post on form 100% supported

Bottom line: Core HTML feature; safe to use in every production form.

💡 Best Practices

✅ Do

  • Use get for searches and read-only filters
  • Use post for login, signup, and data changes
  • Always set action to a meaningful server URL
  • Serve forms over HTTPS in production
  • Validate and sanitize all input on the server

❌ Don’t

  • Assume POST alone makes data secure
  • Send passwords with method="get"
  • Use GET for actions that delete or modify data
  • Confuse method with formmethod on buttons
  • Forget name attributes on fields you need submitted

Conclusion

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

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about method

Bookmark these before building forms.

5
Core concepts
📄 02

<form> only

Form element.

Scope
🔍 03

GET = URL

Query string.

GET
🔒 04

POST = body

Not in address bar.

POST
⚙️ 05

HTTPS + server

Real security.

Security

❓ Frequently Asked Questions

It sets the HTTP method (get or post) used when the form is submitted to the action URL.
GET puts data in the URL query string. POST sends data in the request body. Use GET for searches; POST for logins and data changes.
The <form> element. Submit buttons use formmethod to override the form default for one submission.
No. POST hides data from the URL but does not encrypt it. Use HTTPS and server-side validation for security.
formElement.method = "post" or setAttribute("method", "post").
get. If you omit the attribute, the form behaves as method="get".

Control form submission with method

Practice POST signup forms, GET search, and dynamic form.method in the Try It editor.

Try POST form 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.

5 people found this page helpful