HTML action Attribute
The HTML action attribute specifies the URL where a form's data is sent when the form is submitted. It is used with the <form> element and normally points to a server-side resource that receives and processes the submitted data.
Syntax
The action attribute is placed in the opening <form> tag. Its value is a URL that identifies where the submitted form data should be sent.
<form action="URL">
...
</form>
For example, the following form sends its data to contact.php:
<form action="contact.php" method="post">
...
</form>
Attribute Value
| Value | Description |
|---|---|
URL |
Specifies the URL where the form data is sent when the form is submitted. |
The URL can be relative to the current document or an absolute URL. If the action attribute is omitted, the form is submitted to the URL of the current document.
Elements That Use the action Attribute
The action attribute is currently valid on the <form> element.
| Element | Description |
|---|---|
<form> |
Specifies the URL where the form's submitted data is sent for processing. |
Using the action Attribute
The following form sends the entered name and email address to contact.php when the Submit button is selected:
<form action="contact.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">
<button type="submit">Submit</button>
</form>
The action attribute identifies the destination. The server-side resource at that destination is responsible for processing the submitted values.
Relative and Absolute URLs
A relative URL identifies a destination in relation to the current document or the document's base URL:
<form action="contact.php" method="post">
An absolute URL includes the complete address of the destination:
<form action="https://www.example.com/contact.php" method="post">
Relative URLs are commonly used when the form and its processing resource are on the same website. When submitting information to another origin, consider the security and privacy implications of where the data is being sent.
action and method Attributes
The action and method attributes control different parts of form submission. The action attribute identifies the destination, while the method attribute specifies the HTTP method used to submit the data.
| Attribute | Purpose |
|---|---|
action |
Specifies where the submitted form data is sent. |
method |
Specifies the method used to submit the form data, such as get or post. |
<form action="contact.php" method="post">
...
</form>
Overriding action with formaction
A submit button can use the formaction attribute to provide a different submission URL from the one specified by the form's action attribute.
<form action="save.php" method="post">
<input type="text" name="message">
<button type="submit">Save</button>
<button type="submit" formaction="preview.php">Preview</button>
</form>
Selecting Save submits the form to save.php. Selecting Preview uses the button's formaction value and submits the form to preview.php instead.
Common Mistakes
Do not confuse the action attribute with the method attribute. The action identifies where the data is sent; the method determines how the form is submitted.
<!-- Correct -->
<form action="contact.php" method="post">
...
</form>
Do not assume that specifying an action URL processes the form by itself. The destination must provide the server-side functionality needed to receive and process the submitted data.
When a form collects sensitive information, make sure the submission destination uses HTTPS so the data is encrypted while being transmitted.
Browser Support
Baseline: Widely available indicates a feature has been supported by core browsers for at least 30 months. At this stage, the feature is considered stable and safe for most websites to use without needing to worry about compatibility issues or fallbacks, as it is supported by the vast majority of users' devices and browser versions.
The action attribute on the <form> element is widely supported in current core browsers.
Checking Browser Support
For current browser compatibility information, visit Can I Use? . Search for the HTML element or attribute you want to check. You can also narrow your search by entering an element name and attribute name separated by a colon. Search results can include related HTML features, element attributes, input types, APIs, and other technologies, so select the result that most closely matches the feature you are checking.
Try the action Attribute
The example shows where the action attribute is placed in a form. Edit the form controls or the destination to see how the form markup is structured.
Summary
The HTML action attribute specifies the URL where a form's data is sent when the form is submitted. It is used on the <form> element and works with attributes such as method to control form submission. A submit button can use formaction when a different destination is needed for that particular submission.
