HTML <form> Tag
Our topic in this post is Tag form examples. In hopes that it would provide learners with what they need to learn.
In HTML, the <form> tag is used to create an interactive form on a webpage that allows users to input data and submit it to the server for further processing. The <form> tag is typically used in conjunction with other form-related elements such as input, label, and button tags to create a complete form.
The following HTML form has multiple input fields and a single submit button:
Example: 
Here is an HTML form with checkboxes:
Example: 
The following HTML form has radio buttons:
Example: 
Here is an example of the <form> tag with some CSS applied to it:
Example: 
Tag Form Usage
Using the Tag form <form>, you can create an HTML form that allows users to input information.
The <form> element can be composed of one or more of the following form elements:
Here are some common uses of the <form> tag:
- The most common use of the <form> tag is to create a form that allows users to input data such as their name, email, phone number, and message. The data submitted by the user can then be processed by the server or sent to a specific email address.
- Forms can be used to create user registration pages that allow users to create an account with your website. This typically involves collecting information such as the user’s name, email address, and password.
- Forms can be used to collect feedback or conduct surveys from website visitors. This can be a great way to gather information about the user experience and improve your website.
- A contact form can be created using the <form> tag that allows visitors to send a message or get in touch with the website owner. The form typically includes fields for the user’s name, email address, message, and other relevant information.
- Forms are used extensively in e-commerce websites to collect information such as billing and shipping addresses, payment information, and order details.
- Search forms are commonly used on websites to allow users to search for specific content within the site. The form typically includes a search field and a submit button.
Browser Compatibility
Element | |||||
---|---|---|---|---|---|
<form> | Yes | Yes | Yes | Yes | Yes |
Attributes
Attribute | Value | Overview |
---|---|---|
action | URL | When submitting a form, indicates where you should send the data. |
autocomplete | on off | Sets, whether the form autocomplete, should be enabled or disabled for a form. |
accept-charset | character_set | Provides details about the character encoding used in the form submission. |
name | text | Sets the form’s name. |
enctype | application/x-www-form-urlencoded multipart/form-data text/plain | Provides instructions for encoding the form data (only for method=”post”) before it is submitted to the server. |
method | get post | This method defines how should be sent form data via HTTP. |
rel | external help license next nofollow noopener noreferrer opener prev search | Describes the relationship between a linked resource and the current document. |
target | _blank _self _parent _top | Indicates where it will show the response once the form has been submitted. |
novalidate | novalidate | Instructs the form not to be validated once submitted. |
Attributes
Global
The Tag form <form> is also compatible with HTML’s Global Attributes.
Event
The Tag form <form> is also compatible with HTML’s Event Attributes.<!–
Advertisement
–><!–
mid_content, all: [300,250][336,280][728,90][970,250][970,90][320,50][468,60]
–>
Predefined CSS
Most internet browsers show the Tag form with the following default values:
form { display: block; margin-top: 0em; }
HTML form tag Advantages
The HTML <form> tag has several advantages for creating interactive web pages:
- The <form> tag allows you to specify the type of data that should be entered in each field, such as text, numbers, or email addresses. This helps to ensure that users enter valid data, which can help to reduce errors and improve the overall user experience.
- By using the <form> tag to create forms, you can improve the accessibility of your website for users who rely on assistive technologies such as screen readers. This is because the <form> tag provides a clear structure for form elements, making it easier for users to navigate and understand the content.
- Forms created using the <form> tag can be used to collect data from website visitors, which can be useful for a variety of purposes such as user feedback, surveys, or e-commerce transactions.
- The <form> tag allows you to specify the method used to submit form data to the server, such as HTTP POST or GET, which can help to ensure that sensitive data is transmitted securely.
- The <form> tag can be customized using CSS to create visually appealing and user-friendly forms that match the overall design of your website.
- The <form> tag is supported by all major web browsers, making it a reliable and widely used tool for creating interactive web pages.