HTML Form Tag
HTML Form Tag
The <form> tag in HTML is used to create a form that collects user input. Forms contain
input fields, buttons, checkboxes, dropdowns, and other elements to gather data from
users. The collected data is then sent to a server for processing.
<label for=”name”>Name:</label>
<button type=”submit”>Submit</button>
</form>
Method → Defines how to send data (GET for URL parameters, POST for secure
transmission).
2. Attributes of <form>
Action: Specifies the URL where the form data should be sent.
Method: Defines the HTTP method (GET for URL submission, POST for secure data
transmission).
Target: Specifies where to display the response (_self, _blank, _parent, _top).
Autocomplete: Enables or disables autofill (on allows browser suggestions, off prevents
autofill).
<select name=”country”>
<option value=”us”>USA</option>
<option value=”uk”>UK</option>
</select>
<button type=”submit”>Submit</button>
<button type=”reset”>Reset</button>
4. Example of a Complete Form
<label for=”username”>Username:</label>
<label for=”email”>Email:</label>
<label>Gender:</label>
<label for=”comments”>Comments:</label>
<button type=”submit”>Submit</button>
</form>
Forms are essential for collecting user input and sending it to a server.
Form elements like text fields, checkboxes, and buttons allow different types of data
collection.
Using required, maxlength, and pattern attributes can enhance validation and user
experience.
Forms can be styled using CSS and enhanced with JavaScript for better functionality.