Adding Form Inputs
To collect information from users, you can use the input tag with different type attributes like text, checkbox, and radio.
There are several different input types available in HTML, and choosing the right one can make your form much easier for users to complete. Each type behaves differently depending on whether you want a single answer or a group of selections from the user.
Text Inputs
The text type is the most common input, used for short, single-line text like names or addresses:
Checkboxes
Use the checkbox type when you want to allow the user to select one or more options from a predefined list. Each checkbox should have its own value attribute. If you want a checkbox to be selected by default when the page loads, you can add the checked attribute to the tag:
Radio Buttons
Use the radio type when you want the user to select exactly one option from a group. To link several radio buttons together in a group, you must give them the same name attribute. Just like with checkboxes, you can use the checked attribute to pre-select one of the options:
Notice how they share name="gender". If you gave them different names, the browser wouldn't know they are part of the same choice and would allow the user to select both.
Full Working Example
The following example demonstrates how all three types can be used together in a simple form:
Select Menus
Another way to provide a list of choices is using the select and option elements. This is used for creating dropdown lists, which is particularly handy when you have many options that would take up too much space as a list of checkboxes or radio buttons.
For more details, see Create a Dropdown Select Menu.