Preparing your workspace
HTML forms provide a standard way to collect information from users.
A form groups controls that collect user data. The label element gives a form control a clear name and improves accessibility. The input element supports many types, including text, email, password, number, date, checkbox, and radio. The name attribute is important when form data is submitted because it identifies the submitted field. Required fields can be marked with required. Select is useful when the user should choose from predefined options, while textarea is useful for longer text. Buttons perform actions such as submitting or resetting a form. HTML can also provide basic browser-level validation through attributes such as required, type, minlength, maxlength, min, and max.
A registration form can collect a user's name, email, password, course preference, and agreement to terms.
<form>
<label for="name">Name</label>
<input id="name" name="name" type="text" required>
<label for="email">Email</label>
<input id="email" name="email" type="email" required>
<label for="course">Course</label>
<select id="course" name="course">
<option value="html">HTML</option>
<option value="javascript">JavaScript</option>
</select>
<button type="submit">Register</button>
</form>The browser displays a registration form with name and email fields, a course dropdown, and a submit button.