Free Masterclass on Mar 21
Beginner AI Workshop: Build an AI Agent & Start Your AI Career
In HTML, forms are used to collect data from the user. They allow the user to input information, such as text, numbers, or files, and then send that information to a web server for processing. Forms are often used for a variety of purposes, including:
Forms are created using HTML tags, such as the <form> tag, which defines the start and end of a form, and the <input> tag, which is used to create form fields for the user to fill out. Form fields can include text boxes, dropdown lists, checkboxes, and more. The data collected from the form can be processed using server-side programming languages such as PHP, ASP, or Python.
Forms can also be styled using CSS, which allows developers to customize the appearance of form elements to match the design of their website.
The basic structure of an HTML form consists of the following elements:
Here's an example of a basic HTML form structure:
In this example, the form contains three form fields: a text input for the user's name, an email input for their email address, and a textarea for their message. The for attribute in the <label> tag is used to associate the label with its corresponding form field, and the name attribute in the <input> and <textarea> tags is used to identify the form data when it is submitted. Finally, the form has a submit button that the user can click to submit their data to the server.
Now, we'll take a closer look at some of the most commonly used form attributes in HTML5, including the action attribute, method attribute, name attribute, placeholder attribute, required attribute, disabled attribute, autocomplete attribute, and readonly attribute.
The action attribute is used to specify the URL of the server-side script that will handle the form data when the user submits the form. The value of the action attribute should be a valid URL, and can be either an absolute or a relative URL. If the action attribute is not specified, the form data will be submitted to the current URL.
Here's an example of the action attribute in use:
In this example, the action attribute specifies that the form data should be submitted to the "/submit-form.php" URL.
The method attribute is used to specify the HTTP method that should be used to submit the form data. The two most commonly used methods are "GET" and "POST". When the GET method is used, the form data is appended to the URL as a query string, while with the POST method, the form data is sent in the request body.
Here's an example of the method attribute in use:
In this example, the method attribute specifies that the form data should be submitted using the POST method.
The name attribute is used to identify a form element when the form is submitted. This attribute is used to associate the label with the form element and to access the form data on the server-side script. The name attribute can be used with most form elements, including input fields, select boxes, and text areas.
Here's an example of the name attribute in use:
In this example, the name attribute is used to identify the input field for the username.
The placeholder attribute is used to provide a hint or example text for the user when they are filling out a form field. This attribute is typically used with input fields and text areas.
Here's an example of the placeholder attribute in use:
In this example, the placeholder attribute provides an example of the type of data that the user should enter in the email field.
The required attribute is used to indicate that a form field must be filled out before the form can be submitted. This attribute is typically used with input fields and select boxes.
Here's an example of the required attribute in use:
In this example, the required attribute indicates that the username field must be filled out before the form can be submitted.
The disabled attribute is used to disable a form field so that it cannot be edited or submitted by the user. This attribute is typically used with input fields and select boxes.
Here's an example of the disabled attribute in use:
In this example, the disabled attribute disables the username field so that it cannot be edited by the user.
The autocomplete attribute is used to control whether a form field should be autocompleted by the browser. This attribute is typically used with input fields and text areas.
Here's an example of the autocomplete attribute in use:
In this example, the autocomplete attribute is set to "on" to indicate that the browser should autocomplete the address field.
The readonly attribute is used to make a form field read-only, which means that the user can view the value of the field, but cannot edit or change it. This attribute is typically used with input fields and text areas.
Here's an example of the readonly attribute in use:
In this example, the readonly attribute makes the username field read-only, and sets its initial value to "johndoe".
In conclusion, HTML forms are a crucial component of web development as they allow users to input data that is processed by server-side programming languages. The use of form attributes such as the action attribute, method attribute, name attribute, placeholder attribute, required attribute, disabled attribute, autocomplete attribute, and readonly attribute can enhance the functionality and appearance of forms. By utilizing these attributes, web developers can ensure that their forms are both easy to use and visually appealing, ultimately resulting in a better user experience.
Top Tutorials

Javascript
JavaScript Fundamentals is a beginner-level course that covers the basics of the JavaScript programming language. It covers topics on basic syntax, variables, data types and various operators in JavaScript. It also includes quiz challenges to test your skills.

NodeJS
In this comprehensive Node JS tutorial, the fundamentals are thoroughly covered, preparing learners to create scalable and high-performance web applications. The development environment setup, module usage, asynchronous programming implementation, and integration with databases and external services are all explored. By harnessing the capabilities of server-side JavaScript, web development proficiency can be significantly enhanced.

React Fundamentals
Learn React with the best React JS tutorial and master how to build dynamic, user-friendly web applications using the powerful JavaScript library. Start today!
All Courses (6)
Master's Degree (2)
Fellowship (2)
Certifications (2)