YouTip LogoYouTip

Att Form Action

# HTML
action Attribute The `action` attribute of the `` tag is a fundamental component of web development. It defines the destination where form data should be sent for processing when a user submits the form. --- ## Definition and Usage The `action` attribute specifies the URL of the server-side script or page that will handle the submitted form data. When a user clicks a "Submit" button within a form, the browser packages the input values (such as text fields, checkboxes, and radio buttons) and sends them to the address specified in the `action` attribute. --- ## Syntax ```html
``` ### Attribute Values | Value | Description | | :--- | :--- | | **Absolute URL** | Points to an external website or a complete web address (e.g., `action="https://www.example.com/submit-form"`). | | **Relative URL** | Points to a file or endpoint within the same website (e.g., `action="/api/submit-form"` or `action="demo_form.php"`). | | **Empty String / Omitted** | If left empty or omitted in HTML5, the form will submit to the current page's URL. | --- ## Code Examples ### Example 1: Basic Form Submission (Relative URL) In this example, when the user submits the form, the data is sent to a local file named `demo_form.html` using the default `GET` method. ```html




``` ### Example 2: Submitting to an External API (Absolute URL) This example demonstrates sending form data to an external server using the `POST` method, which is ideal for sensitive data or database modifications. ```html




``` --- ## Differences Between HTML 4.01 and HTML5 * **HTML 4.01:** The `action` attribute was **required** for a `
` element to be valid. * **HTML5:** The `action` attribute is **optional**. If it is not specified, the browser defaults to submitting the form data to the URL of the current page. --- ## Browser Support The `action` attribute is a core feature of HTML and is fully supported by all modern and legacy web browsers: * Google Chrome * Mozilla Firefox * Microsoft Edge / Internet Explorer * Apple Safari * Opera --- ## Key Considerations & Best Practices ### 1. Choosing the Right HTTP Method (`method`) The `action` attribute works hand-in-hand with the `method` attribute (typically `GET` or `POST`): * Use **`GET`** (default) for non-sensitive actions like search forms. The data will be appended to the URL specified in the `action` attribute. * Use **`POST`** for actions that modify data (like registration, login, or file uploads). The data is sent in the HTTP request body, keeping it out of the browser history and address bar. ### 2. Overriding the Form Action In HTML5, you can override the form's `action` attribute on a per-button basis using the `formaction` attribute on an `` or `
← Att Form AutocompleteAtt Form Accept Charset β†’