HTML: the action attribute

The action attribute tells a form which URL should receive its submitted data.

What you will learn

Basic example

<form action="/search" method="get">
  <label>Keyword <input name="q"></label>
  <button type="submit">Search</button>
</form>

When the form is submitted, the browser sends the successful controls to /search. The name value becomes the parameter name, so a keyword might produce /search?q=html.

action and method

Different destinations for buttons

<form action="/orders/submit" method="post">
  <button type="submit">Place order</button>
  <button type="submit" formaction="/orders/draft">Save draft</button>
</form>

The second button overrides the form's action for that submission. This is useful when related actions share the same fields but should use different endpoints.

Common mistakes