- HTML Tutorial
- HTML - Home
- HTML - Introduction
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Headings
- HTML - Paragraphs
- HTML - Fonts
- HTML - Blocks
- HTML - Style Sheet
- HTML - Formatting
- HTML - Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- 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 Color Names & Values
- HTML - Color Names
- 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 Picker
- HTML References
- HTML - Cheat Sheet
- 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
HTML action attribute is used within a <form> element to specify where the form data should be sent when the form is submitted.
This attribute value can be overridden by the form tag's action attribute, which means if we specify this attribute with <input type = submit>, when the user submits the form, it will redirect according to the form tag's action 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
<form action = "URL"></form>
Applies On
Below listed element allow using of the HTML action attribute.
Element | Description |
---|---|
<form> | HTML <form> tag is used to specify the input field. |
Examples of HTML action attribute
Here are some examples that shows different usage ways of action attribute
Action attribute with an existing URL
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. The below code will generate an output consisting of the input field along with a clickable button on the webpage. when the user clicks the button the form gets submitted successfully.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML 'action' attribute</title> <style> form { width: 250px; padding: 10px; background-color: skyblue; border-radius: 10px; } input { padding: 10px; width: 200px; } button { padding: 10px; width: 100px; cursor: pointer; } </style> </head> <body> <!--HTML 'action' attribute--> <h3>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>
Action attribute with wrong URL
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. The below code will generate an output consisting of the input field along with a clickable button displayed on the webpage. When the user tries to submit the form it will displays error because of the URL we have given.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML 'action' attribute</title> <style> form { width: 330px; padding: 10px; background-color: skyblue; 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>
Supported Browsers
Attribute | |||||
---|---|---|---|---|---|
action | Yes | Yes | Yes | Yes | Yes |
To Continue Learning Please Login
Login with Google