HTML action attribute
action Attribute
The action attribute specifies where to send form data when a form is submitted. It defines the URL of the server-side script (e.g., PHP, Node.js, Python) that processes the form data.
Supported Element
- <form>
Syntax
<form action="URL" >...</form>
Values
- URL: The address where the form data is sent.
- Can be a relative path (e.g., "/submit-form") or absolute URL (e.g., "https://api.example.com/submit").
- If omitted, the form submits to the current page URL (default behavior).
Key Notes
- Use the method attribute to specify GET (data in URL) or POST (data in request body).
- Example: <form action="/login" method="POST">.
1. HTML5 Support: Valid in HTML5 and all HTML versions.
2. Form Submission Methods:>
3. Override with formaction: Individual submit buttons can override the form’s action using the formaction attribute.
<button type="submit">Save Draft</button> <button type="submit" formaction="/publish">Publish</button>
Example (Modern HTML5)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login Form</title>
</head>
<body>
<form action="/login" method="POST">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required><br>
<button type="submit">Sign In</button>
</form>
</body>
</html>
Result
![html-action-attribute-with-form](https://www.w3resource.com/w3r_images/html-action-attribute-with-form.png)
View this example in a separate browser window
Example of HTML action attribute with form.
Best Practices
- Use method="POST" for sensitive data (passwords, payments).
- Always validate form data on the server-side, even with client-side checks.
- For empty action, ensure the current page handles form resubmission correctly (e.g., avoid duplicate submissions).
Browser Compatibility
- Supported in all browsers (Chrome, Firefox, Safari, Edge, etc.).
Previous: HTML accesskey attribute
Next: HTML align attribute
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics