YouTip LogoYouTip

Att Form Method

# HTML <form> `method` Attribute The `method` attribute of the `
` tag specifies how to send form-data to the server-side resource defined in the `action` attribute. Form data can be sent as URL variables (using `method="get"`) or as an HTTP post transaction (using `method="post"`). --- ## Browser Support The `method` attribute is fully supported by all major modern web browsers: * Google Chrome * Mozilla Firefox * Microsoft Edge / Internet Explorer * Safari * Opera --- ## Syntax ```html ``` ### Attribute Values | Value | Description | | :--- | :--- | | **`get`** | **Default.** Appends the form data to the URL in name/value pairs: `URL?name=value&name=value`. | | **`post`** | Sends the form data as an HTTP post transaction, enclosing it within the body of the HTTP request. | --- ## GET vs. POST: Key Differences and Considerations Choosing the correct HTTP method is critical for application security, performance, and user experience. ### When to use GET (`method="get"`) * **Data Visibility:** Form data is appended directly to the URL. **Never use GET to send sensitive data** (such as passwords, credit card numbers, or personal information), as it will be visible in the browser's address bar, browser history, and server logs. * **Length Restrictions:** URLs have length limitations (typically around 2048 to 3000 characters depending on the browser and server). Do not use GET for forms with large amounts of text or file uploads. * **Bookmarking:** Because the data is in the URL, users can bookmark the resulting page. This is ideal for search forms, filtering systems, or navigation-based queries (e.g., Google Search). * **Idempotency:** GET requests should be idempotent, meaning they only retrieve data and do not modify the state of the server. ### When to use POST (`method="post"`) * **Data Privacy:** Form data is packaged inside the body of the HTTP request. It is not visible in the URL, making it much safer for sensitive information. * **No Size Limits:** There are no size restrictions on the data sent via POST. This method is required for uploading files (``). * **Bookmarking:** Pages resulting from a POST request cannot be bookmarked directly because the form data is not stored in the URL. * **State Changes:** POST should be used for any action that modifies server state, such as creating a new user, updating a database, or deleting a record. --- ## Code Examples ### Example 1: Submitting a Form Using the GET Method This is ideal for search queries or non-sensitive data retrieval. ```html

``` *If a user types "HTML tutorial" and submits, the browser will redirect to: `search_results.html?query=HTML+tutorial`* ### Example 2: Submitting a Form Using the POST Method This is the standard approach for user registration, logins, and submitting sensitive data. ```html




``` *When submitted, the credentials are sent securely in the HTTP request body, keeping the URL clean and secure.* --- ## HTML 4.01 vs. HTML5 There are no differences in the core behavior of the `method` attribute between HTML 4.01 and HTML5. However, HTML5 introduces the `formmethod` attribute, which allows you to override the form's `method` attribute on a per-button basis (e.g., ``).
← Att Form NameAtt Form Enctype β†’