action

The action attribute in HTML forms defines the URL where the form data will be sent. The method attribute determines how the data is transmitted, either using GET or POST.

action attribute

The action attribute in HTML forms specifies the URL where the form data is sent when submitted. The method attribute determines how the data is sent (GET or POST).

Syntax

index.html
<form action="URL">

The action attribute in an HTML form specifies the URL where the form data will be sent for processing. If it's not provided, the data will be submitted to the same URL where the form is located. For example, in a login form, the action could point to a server-side script that handles the authentication process.

Example

Here’s a basic HTML form example illustrating how the action attribute is used:

index.html
<form method="POST">
  <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>

When the <form> is submitted, the data will be sent to the "submit" URL using the POST method. A script at this URL will handle and process the form data.

Values

  • URL
    • A URL pointing to a script, which can be either an internal or external URL, or even a JavaScript function.

Applies To

The action attribute can be used on the following html elements.

ElementsAttributes
<form>action

Conclusion

The action attribute in HTML forms determines the URL where the form data will be sent upon submission. It can point to an internal or external URL. If omitted, the data is submitted to the same URL as the page the <form> is on.