- HTML Tutorial
- HTML - Home
- HTML - History and Evolution
- HTML - Overview
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Headings
- HTML - Paragraphs
- HTML - Quotations
- HTML - Comments
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Style Sheet
- HTML - CSS Classes
- HTML - CSS IDs
- HTML - Images
- HTML - Image Map
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Iframes
- HTML - Blocks
- HTML Backgrounds
- HTML - Backgrounds
- HTML Colors
- HTML - Colors
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Code Builder
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - action Attribute
The HTML action attribute is used to specify a URL that processes the form submission. It defines an action to be performed when the form is submitted.
This attribute value can be overridden by the formaction attribute, which means if we specify this attribute with <input type = submit>, when the user submits the form, it will redirect according to the formaction attribute source URL, not according to the action attribute.
The ‘action’ attribute works with the <form> element. This attribute is ignored when the method =dialog attribute is set within the <form> element.
Syntax
Following is the syntax for HTML 'action’ attribute −
<form action = "value"></form>
Example
In the following example, we are using the HTML ‘action’ attribute within the <form> element to define the action to be performed when the form is submitted.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML 'action' attribute</title> <style> form { width: 250px; padding: 10px; background-color: aquamarine; border-radius: 10px; } input { padding: 10px; width: 200px; } button { padding: 10px; width: 100px; cursor: pointer; } </style> </head> <body> <!--HTML 'action' attribute--> <h3>Example of the HTML 'action' attribute</h3> <form action="welcome.html" method="GET"> <h1>Login Page</h1> <input type="text" placeholder="Username" name="uname" required> <br> <br> <input type="password" placeholder="Password" name="password" required> <br> <br> <button>Login</button> </form> </body> </html>
On running the above code, it will generate an output consisting of the input field along with a click button on the webpage. when the user click the button the form gets submitted successfully.
Example
Considering the another scenario, where we are going to use the action attribute with the form tag and assign the wrong URL which displays error on submission of the form.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML 'action' attribute</title> <style> form { width: 330px; padding: 10px; background-color: rgb(7, 32, 158); border-radius: 10px; color: white; } input { padding: 12px; width: 300px; } button { padding: 12px; width: 100px; cursor: pointer; } form h1 { text-align: center; font-family: sans-serif; letter-spacing: 2px; } </style> </head> <body> <!--HTML 'action' attribute--> <h3>Example of the HTML 'action' attribute</h3> <form action="/action_page.php" method="GET"> <h1>Login</h1> <input type="text" placeholder="Username" name="uname" required> <br> <br> <input type="password" placeholder="Password" name="password" required> <br> <br> <button>Login</button> </form> </body> </html>
When we run the above code, it will generate an output consisting of the input field along with a click button displayed on the webpage. when the user tries to submit the form it will displays error because of the URL we have given.
To Continue Learning Please Login
Login with Google