Lesson 2.5: Forms – Input, Textarea, Select, Buttons
Forms in HTML are used to collect user input, such as text, numbers, selections, and files. They are essential for interaction between users and websites, like signing up, logging in, or submitting feedback.
1. The <form> Element
All form controls are placed inside a <form> element.
-
action: Defines the URL where form data is sent.
-
method: Defines how data is sent (
getorpost).
2. Input Fields (<input>)
The <input> element is the most versatile form control. It changes its behavior using the type attribute.
Common Input Types:
3. Textarea (<textarea>)
For multi-line text input such as comments or messages.
4. Select Dropdown (<select>)
Used to create a dropdown menu.
-
<option>: Defines the items inside the dropdown. -
The
selectedattribute can make an option selected by default.
5. Buttons (<button> and <input type="submit">)
Buttons allow users to submit a form or trigger actions.
-
type="submit"→ submits the form. -
type="reset"→ clears the form fields. -
type="button"→ custom actions (often used with JavaScript).
6. Example – Complete Registration Form
✅ Key Takeaways:
-
Use
<input>for single-line fields. -
Use
<textarea>for multi-line input. -
Use
<select>and<option>for dropdown menus. -
Use
<button>or<input type="submit">to submit forms. -
Always enclose form controls inside a
<form>element.
