- 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 - <form> Tag
A form can be created in HTML using the <form> tag to collect user input on a website. A user's name, address, and phone number are just a few of the possible options on this form that can be used to collect data about the user or to ask their opinions on a certain product.
These forms take data, which is then provided in HTML format to the URL that is supplied. These form tags can be used to build login functionality or registration forms on a website, etc.
Syntax
Following is the syntax for HTML <form> tag −
<form>.....</form>
Specific Attributes
The HTML <select > tag also supports the following additional attributes −
S.No. | Attribute & Description |
---|---|
1 | accept Specifies a comma-separated list of content types that the server accepts. |
2 | accept-charset Specifies a list of character encodings that the server accepts. The default value is "unknown". |
3 | action Specifies a URI/URL of the back-end script that will process the form. |
4 | autocomplete Specifies whether form should have autocomplete on or off< |
5 | enctype The mime type used to encode the content of the form. |
6 | name Defines a unique name for the form. |
7 | novalidate Specifies that the form should not be validated when submitted. |
8 | method Specifies the HTTP method to use when the form is submitted. Possible values |
Example
In the following program, we are using HTML <form> tag to create a form for user input. This form (user login form) will have three input fields with type 'text', 'password', and ‘button’.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML form tag</title> </head> <body> <!--create a html form--> <h3>User login form</h3> <form> Username : <input type="text"> <br> <br> Password : <input type="password"> <br> <input type="button" value='Login'> </form> </body> </html>
When we run the above code, it will generate an output consisting of the input fields along with a click button on the webpage.
Example
Let's look at the following example, where we are going to use form tag and appling CSS to the input fields.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML form tag</title> <style> form { width: 300px; height: 260px; background-color: blueviolet; color: white; border-radius: 10px; margin: 10px auto; } form h3 { text-align: center; position: relative; top: 5px; } form label { position: relative; margin: 10px 10px; top: 10px; } form input { position: relative; top: 10px; margin: 10px 10px; } </style> </head> <body> <!--create a html form--> <form> <h3>User signup form</h3> <label>Name</label> <input type="text" placeholder="Name"> <br> <label>Email</label> <input type="email" placeholder="Email"> <br> <label>Phone</label> <input type="number" placeholder="Phone"> <br> <label>Gender</label> <br> <label>Male</label> <input type="radio"> <label>Female</label> <input type="radio"> <br> <input type="button" value="Submit"> </form> </body> </html>
On running the above code, the output window will pop up displaying the input field , radio buttons along with a click button applied with a CSS on the webpage.
To Continue Learning Please Login
Login with Google