The method attribute on <form> sets which HTTP method is used to send the form's data — almost always either GET or POST.
Syntax
<form action="/search" method="get">
<form action="/login" method="post">
Basic Example
<form action="/search" method="get">
<label for="q">Search</label>
<input type="search" id="q" name="q">
<button type="submit">Search</button>
</form>
Browser output: submitting this form navigates to something like /search?q=python+course — with GET, the form's data becomes visible right in the URL itself.
How It Works
The value of method determines exactly how the browser packages and sends the form's data — see get-vs-post for the full comparison and when to use each.
Important Attributes
| Value | Behavior |
|---|---|
get | Appends data as visible query parameters in the URL — this is the default if method is omitted entirely |
post | Sends data in the invisible request body, not the URL |
Real-World Example
<form action="/enroll" method="post">
...personal details, potentially including sensitive info...
</form>
An enrollment form handling personal (and potentially sensitive) information — POST is the correct choice here specifically so that data never ends up visible in the URL, browser history, or server access logs.
Common Mistakes
- Leaving out
methodentirely and unintentionally getting the default (GET) behavior on a form handling sensitive data like a password - Using
GETfor a form that changes data on the server (like deleting an item) — see get-vs-post for why this matters
Best Practices
- Always set
methodexplicitly, never relying on the implicit default - Use
GETonly for forms that simply retrieve/filter data (like a search box), andPOSTfor anything that submits, creates, or changes data
Accessibility Considerations
No direct accessibility impact — this attribute affects data transmission, not the field's presentation or interaction.
SEO Considerations
A GET search form's results become bookmarkable, shareable URLs — genuinely useful for SEO and usability on things like search or filter pages, unlike a POST-based equivalent.
Browser & Modern HTML Notes
Stable and unchanged across HTML versions — the method attribute has worked identically since forms were first introduced.
Mini Practice
- Build a search form using
method="get"and observe how the submitted value appears in the URL. - Explain why a login form should never use
method="get".