MyInternships.in

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.

The basic pattern
Example
<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.

A search form that submits to an action URL
Example
<!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

formaction lets one form submit to two places
Example
<!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

ValueDescription
/applyA relative URL on the same site
https://example.com/applyAn absolute URL to any server
(empty)Submits to the current page URL
mailto:you@example.comOpens 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.

Related HTML Topics

Keep learning with these closely related tutorials.

Ready to use your HTML skills?

Find web development internships and fresher jobs across India.

Browse Web Dev Internships