HTML action Attribute

The HTML action attribute specifies where the form-data should be sent when the form is submitted. Its attribute value (URL) determines where the data must be sent after the form submission. The URL can have the following values:

  • absolute URL, which refers to another website link.
  • relative URL, which refers to a file within a webpage.

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

Syntax

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

Example of the HTML action 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 Your Knowledge

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

Quiz Time: Test Your Skills!

Ready to challenge what you've learned? Dive into our interactive quizzes for a deeper understanding and a fun way to reinforce your knowledge.

Do you find this helpful?