HTML action Attribute
Description
The action attribute in HTML forms specifies the URL to which the form's data is sent when the form is submitted. This attribute is essential for defining the server-side script or endpoint that will process the submitted form data. The method for sending this data is determined by the form's method attribute, which can be set to "GET" (default) or "POST".
In essence, the action attribute acts as the destination for the form data, guiding it to the correct server location for processing. If the action attribute is omitted, the form data will be sent to the same URL as the form itself. This is useful for cases where form processing and display are handled by the same URL, but specifying an action provides greater control and flexibility over form data handling.
For example, in a login form, the action attribute might be set to a URL that points to a script on the server designed to authenticate users. This script would receive the login credentials, verify them against stored data, and then respond accordingly, such as granting access to a restricted area or displaying an error message if the credentials are incorrect.
Here's a simple HTML form example demonstrating the use of the action attribute:
<form action="submit_form.php" 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">
<input type="submit" value="Submit">
</form>
In this example, when the form is submitted, the data entered into the form will be sent to "submit_form.php" using the POST method. The script at "submit_form.php" will then process the form data accordingly.
Syntax
<form action="URL">
Values
- URLA URL to a script, can be an internal or external URL. It can also be a JavaScript function.
Applies To
Example
Browser Support
The following information will show you the current browser support for the HTML action attribute. Hover over a browser icon to see the version that first introduced support for this HTML attribute.
This attribute is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 28th March 2024
