HTML Attributes
HTML action Attribute
The action attribute defines the URL that processes a form's data when it is submitted. It works hand in hand with the method attribute.
The action Attribute
The action attribute belongs to the <form> element. It holds the URL of the server-side program or endpoint that receives and processes the form data when the user submits the form. It works together with the method attribute, which decides whether the data is sent as a GET or POST request.
If action is omitted, the form submits to the current page URL.
Syntax
Syntax: <form action="url" method="post">. The value is any valid URL, absolute or relative.
<form action="/api/apply" method="post"> ... </form>Example
Run the example — the form's action points to a search endpoint and the method decides how the data travels.
<!DOCTYPE html>
<html>
<body>
<form action="https://duckduckgo.com/" method="get">
<label for="q">Search the web</label><br>
<input type="search" id="q" name="q" placeholder="internships in Pune"><br><br>
<button type="submit">Search</button>
</form>
</body>
</html>More Examples
Overriding the action per button
<!DOCTYPE html>
<html>
<body>
<form action="/save" method="post">
<input type="text" name="note" placeholder="Write a note">
<button type="submit">Save</button>
<button type="submit" formaction="/save-and-share">Save & Share</button>
</form>
</body>
</html>Attribute Values
| Value | Description |
|---|---|
| /apply | A relative URL on the same site |
| https://example.com/apply | An absolute URL to any server |
| (empty) | Submits to the current page URL |
| mailto:you@example.com | Opens an email client (not recommended for real forms) |
You can override a form's action per submit button using the formaction attribute on <button> or <input type="submit">, which is handy when one form has multiple submit targets.
Key Takeaways
- action sets where the form's data is sent on submit.
- It belongs to the <form> element and works with method.
- Values can be relative or absolute URLs.
- Omitting action submits to the current page.
- formaction on a button can override the form's action.
