Coding Hubs School of AI – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 8448811540
Back to HTML Notes
Topic #729

form method

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

ValueBehavior
getAppends data as visible query parameters in the URL — this is the default if method is omitted entirely
postSends 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 method entirely and unintentionally getting the default (GET) behavior on a form handling sensitive data like a password
  • Using GET for a form that changes data on the server (like deleting an item) — see get-vs-post for why this matters

Best Practices

  • Always set method explicitly, never relying on the implicit default
  • Use GET only for forms that simply retrieve/filter data (like a search box), and POST for 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

  1. Build a search form using method="get" and observe how the submitted value appears in the URL.
  2. Explain why a login form should never use method="get".

Related HTML Notes

Want to go beyond the notes?

Join Coding Hubs School of AI's HTML course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →