Nearby lessons
17 of 24π HTML Forms
π What are HTML Forms?
HTML forms are essential for collecting user inputs on websites. π
They allow users to enter data such as text, email, files, and more, which is then sent to a server for processing.
Main tag: <form> β Contains controls like <input>, <textarea>, <select>, and buttons.
π§ Basic Form Structure
A simple form includes text and email inputs with a submit button.
Code Example
PREVIEW READY
βοΈ Checkbox and π Radio Buttons
Use checkboxes for multiple selections and radio buttons for single choice selection.
Code Example
PREVIEW READY
π Textarea and β¬οΈ Select Dropdown
Use
<textarea> for multi-line input and <select> for dropdown menus.Code Example
PREVIEW READY
β Form Validation Example
You can use attributes like
required, pattern, and minlength for validation.Code Example
PREVIEW READY
π Form Attributes
| Attribute | Description |
|---|---|
action | Where to send the form data. |
method | HTTP method to use (GET or POST). |
enctype | Encoding type (e.g. multipart/form-data for files). |
autocomplete | Enable or disable browser autocomplete. |
target | Specifies where to display the response (e.g. _blank). |
π§© Input Attributes
| Attribute | Description |
|---|---|
type | Defines the input type (text, email, password, etc.). |
name | Used to identify the input value on form submission. |
required | Makes the field mandatory to fill. |
placeholder | Shows a hint inside the input field. |
readonly | Makes the input non-editable. |
π§ Test Your Knowledge
3 QuestionsProgress: 0 / 3
Keep Going!HTML Iframes