HTML forms are an essential part of any website or web application. They allow users to interact with a website by submitting data, such as filling out a contact form, purchasing, or posting a comment.
Here’s a simple example of an HTML form:
<form>
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password"><br><br>
<input type="submit" value="Submit">
</form>
Let’s break down this code:
- The
<form>
element is the container for the form and all its elements. - The
<label>
element is used to give a text description for each form control. Thefor
attribute is used to associate the label with a specific form control using itsid
. - The
<input>
element is the most common form of control and is used to receive data from the user. Thetype
attribute specifies the type of form control, such as text, email, password, checkbox, radio button, etc. Theid
andname
attributes are used to give the form control a unique identifier. - The
<input type="submit">
element is used to submit the form data to a server for processing. Thevalue
attribute specifies the text that will be displayed on the button.
Note: In this example, the form data will be sent to the same page for processing, but in a real-world scenario, you would send the data to a server-side script (e.g., PHP, Python, Ruby, etc.) for processing.
This is just a basic example of an HTML form, and many more form elements and attributes are available for you to use. If you want to learn more about HTML forms, I recommend checking out the official W3Schools HTML Forms tutorial: (https://www.w3schools.com/html/html_forms.asp)