HTML Form Elements
This chapter describes the different HTML form elements.
Common Form Elements
- <input>: The most used form element. It can be displayed in many ways, depending on the
typeattribute (e.g., text, password, checkbox, radio, submit). - <label>: Defines a label for many form elements, which improves accessibility.
- <select>: Defines a drop-down list.
- <textarea>: Defines a multi-line text input control.
- <button>: Defines a clickable button.
- <fieldset> and <legend>: Used to group related data in a form with a caption.
Example: The <select> Element
html
<label for="cars">Choose a car:</label>
<select id="cars" name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>Example: The <textarea> Element
html
<textarea name="message" rows="10" cols="30">
The cat was playing in the garden.
</textarea>Example: The <button> Element
html
<button type="button" onclick="alert('Hello world!')">Click Me</button>Test Yourself with an Exercise
Which element is used to create a multi-line text input field?