Menu
HTML Forms
An HTML form is used to collect user input. The user input is most often sent to a server for processing.
Example
<!DOCTYPE html>
<html>
<body>
<h2>HTML Forms</h2>
<form action=”/action_page.php”>
<label for=”fname”>First name:</label><br>
<input type=”text” id=”fname” name=”fname” value=”John”><br>
<label for=”lname”>Last name:</label><br>
<input type=”text” id=”lname” name=”lname” value=”Doe”><br><br>
<input type=”submit” value=”Submit”>
</form>
<p>If you click the “Submit” button, the form-data will be sent to a page called “/action_page.php”.</p>
</body>
</html>
The <form> Element
The HTML <form> element is used to create an HTML form for user input:
<form>
.
form elements
.
</form>
The <form> element is a container for different types of input elements, such as: text fields, checkboxes, radio buttons, submit buttons, etc.
All the different form elements are covered in this chapter: HTML Form Elements.
The <input> Element
The HTML <input> element is the most used form element.
An <input> element can be displayed in many ways, depending on the type attribute.
Here are some examples:
Text Fields
The <input type="text"> defines a single-line input field for text input.