👀 Live Preview
A simple form with action="/submit-form" and method="post":
In a real app, clicking Submit would POST to /submit-form.

In HTML, the action attribute plays a crucial role in defining the URL to which a form should be submitted. It is used within the <form> element to specify the server-side script or endpoint that will process the data submitted by the user.
Where form data goes.
Same-domain endpoints.
Cross-domain forms.
Pair with method.
Set action dynamically.
Use HTTPS endpoints.
actionThe primary purpose of the action attribute is to provide the browser with the destination URL where the form data should be sent for processing. This URL could point to a server-side script, a web service, or any other resource capable of handling form submissions.
action defines where data goes; method defines how it is sent (GET or POST). Always set both intentionally.
Add action to the opening <form> tag with a valid URL as its value:
<form action="/submit-form" method="post">
<!-- form fields -->
</form><form> elements.method, enctype, and accept-charset as needed.The action attribute accepts various values, typically represented as URLs. These values can be absolute or relative URLs, allowing for flexibility in specifying where the form data should be sent. Here are some examples:
/submit-form submits to the /submit-form endpoint on the same domain.https://example.com/process-form sends data to a specific absolute URL, allowing cross-domain form submissions.action="" submits the form to the same URL the page originated from (the current document URL).<!-- Relative path -->
<form action="/submit-form" method="post">...</form>
<!-- Absolute URL -->
<form action="https://example.com/process-form" method="post">...</form>
<!-- Submit to current page -->
<form action="" method="get">...</form>| Use Case | action Value | Notes |
|---|---|---|
| Contact form (POST) | /contact | Same-domain handler |
| Search box (GET) | /search | Query string in URL |
| Third-party service | https://api.example.com/submit | Absolute URL |
| Process on same page | "" or omit | Current document URL |
| Applicable element | <form> | Form element only |
| Element | Supported? | Notes |
|---|---|---|
<form> | Yes | Primary and only standard use |
<input> | No | Place action on the parent form |
<button> | No | Buttons submit their parent form |
POST contact forms, dynamic JavaScript action URLs, and GET search forms.
A simple form with action="/submit-form" and method="post":
In a real app, clicking Submit would POST to /submit-form.
The action attribute is added to the opening <form> tag and takes the form of a URL. Here’s a basic example:
<form action="/submit-form" method="post" accept-charset="UTF-8">
<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, the form data will be submitted to the /submit-form URL using the HTTP POST method. The server endpoint at that path receives the name and email fields for processing.
You can dynamically set the action attribute using JavaScript to modify the form submission behavior based on user interactions or other conditions. Here’s a simple illustration:
<form id="dynamicForm" method="post">
<!-- form fields -->
</form>
<script>
document.getElementById("dynamicForm").action = "/submit-form";
</script>In this script, the action attribute of a form with the id dynamicForm is set to /submit-form. This flexibility is useful when the submission endpoint needs to change based on user selections or application state.
Use action with method="get" to append form fields as query parameters in the URL:
<form action="/search" method="get" role="search">
<input type="search" name="q" placeholder="Search...">
<button type="submit">Search</button>
</form>With GET, the browser builds a URL from action plus encoded field values. Search forms commonly use this pattern so results can be bookmarked and shared.
<label for="..."> so users know what data the form collects.action.Define the submission URL in HTML or JavaScript.
Inputs, selects, and textareas collect the data to send.
GET appends query params; POST sends a request body.
The endpoint at action processes the submission and responds.
The action attribute is supported in all modern browsers on form elements. It has been part of HTML since early versions.
All major browsers honor action on <form> elements.
Bottom line: Use action confidently on every form that submits data to a server.
action is a valid, accessible endpointaction with the correct method (GET vs POST)action at endpoints you do not control without reviewThe action attribute is a fundamental aspect of HTML forms, guiding the browser on where to send user-entered data. Understanding how to use and customize this attribute is crucial for creating effective and functional web forms.
Whether you use a relative path, an absolute URL, or set the destination dynamically with JavaScript, always ensure your server endpoint is ready to receive, validate, and respond to submissions securely.
actionBookmark these before your next form.
Where data is sent.
BasicsOn <form> element.
ScopeFlexible URL values.
Valuesform.action at runtime
DynamicProtect sensitive data
Security<form> is the standard element. Other elements do not use action directly.formElement.action based on user choices or form state.action attribute has universal support on form elements.Practice the action attribute with POST and GET examples in the Try It editor.
5 people found this page helpful