W3docs

HTML action Attribute

The HTML action attribute specifies where the form-data should be sent when the form is submitted. Read and find out on what element you can use this attribute.

The HTML action attribute specifies where form data should be sent when the form is submitted. Its value (URL) determines the destination for the submitted data. The URL can be:

  • absolute, which refers to a full URL including the protocol and domain.
  • relative, which refers to a path relative to the current document.

You can use this attribute only on the <form> element.

Syntax

Syntax of HTML action Attribute

<form action="URL"></form>

Example of the HTML action attribute:

Example of the <span class="attribute">"action"</span> attribute

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <form action="/form/submit">
      <label for="fname">Name</label>
      <input type="text" name="FirstName" id="fname" value="Mary"/><br /><br />
      <label for="lname">Surname</label>
      <input type="text" name="LastName" id="lname" value="Thomson"/><br /><br />
      <input type="submit" value="Submit"/>
    </form>
  </body>
</html>

In this example we used relative path, and the data will be sent to the /form/submit URL within the same domain as the current page. As mentioned, you can use absolute path here to address a URL from another domain, like https://example.com/some-page.

Practice

Practice

What is the function of the HTML 'action' attribute?