HTML & CSS References
An HTML Form is used to collect input from a user. The information collected can then be sent to a server, or accessed by a Developer, or more.
HTML Form Elements
<form> element is used to create an HTML form for user input. Within the
<form> tags, we can nest different types of input elements like text fields, checkboxes, radio buttons, etc.
<input> element is the most used form element. The reason for that is because the
<input> element can be displayed in many different ways, depending on the type attribute.
<!-- Display a single-line text input field --> <input type=“text”> <!-- Display a checkbox (for selecting zero or more of many choices) --> <input type=“checkbox”> <!-- Display a radio button (for selecting one of many choices) --> <input type=“radio”>
<label> element is used to define a label for a given input field. We use specific attributes in order to connect the label to an input field.
- There will be an id attribute on the input
- There will be a for attribute on the label, with the same value as the id attribute on the input
This will connect the label and the input together, allowing better accessibility and use for our users.
HTML Form Attributes
<form> tag has specific attributes that define the behavior of the form itself.
The action attribute on the form defines what happens when the form is submitted.
The method attribute defines which HTTP method to use when submitting the form data
The target attribute on the form specifies where to display the form response.
HTML Form Validation
HTML form validation is used to validate form data before the data is forwarded or saved in any format. Automatic validation can be as easy as adding a required attribute to any given form input, requiring the input to be filled before submission. Unfortunately, with just HTML there is no real way to validate the data itself, just that it exists.
Learn HTML & CSS Today
Get hands-on experience writing real code while you learn with interactive tutorials in our free online learning platform – no downloads or complicated setup required.
- Free and fun
- Designed for beginners
- No download or setup required