CSS Portal

HTML action Attribute

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
action
HTML AttributeThis attribute is supported by all modern browsers.
Updated 28th March 2024

Description

The action attribute in HTML forms specifies the URL to which the form's data is sent when the form is submitted. This attribute is essential for defining the server-side script or endpoint that will process the submitted form data. The method for sending this data is determined by the form's method attribute, which can be set to "GET" (default) or "POST".

In essence, the action attribute acts as the destination for the form data, guiding it to the correct server location for processing. If the action attribute is omitted, the form data will be sent to the same URL as the form itself. This is useful for cases where form processing and display are handled by the same URL, but specifying an action provides greater control and flexibility over form data handling.

For example, in a login form, the action attribute might be set to a URL that points to a script on the server designed to authenticate users. This script would receive the login credentials, verify them against stored data, and then respond accordingly, such as granting access to a restricted area or displaying an error message if the credentials are incorrect.

Here's a simple HTML form example demonstrating the use of the action attribute:

<form action="submit_form.php" 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>

In this example, when the form is submitted, the data entered into the form will be sent to "submit_form.php" using the POST method. The script at "submit_form.php" will then process the form data accordingly.

Syntax

<form action="URL">

Values

  • URLA URL to a script, can be an internal or external URL. It can also be a JavaScript function.

Applies To

Example

<form action="formscript.php" method="post">
<label for="fname">First Name:</label><br>
<input type="text" id="fname" name="firstname"><br><br>
<label for="lname">Last Name:</label><br>
<input type="text" id="lname" name="lastname"><br><br>
<input type="submit" value="Submit">
</form>
Open in editor

Browser Support

The following information will show you the current browser support for the HTML action attribute. Hover over a browser icon to see the version that first introduced support for this HTML attribute.

This attribute is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee