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
Loading Editor...
Live Preview

β˜‘οΈ Checkbox and πŸ”˜ Radio Buttons

Use checkboxes for multiple selections and radio buttons for single choice selection.
Code Example
PREVIEW READY
Loading Editor...
Live Preview

πŸ“ Textarea and ⬇️ Select Dropdown

Use <textarea> for multi-line input and <select> for dropdown menus.
Code Example
PREVIEW READY
Loading Editor...
Live Preview

βœ… Form Validation Example

You can use attributes like required, pattern, and minlength for validation.
Code Example
PREVIEW READY
Loading Editor...
Live Preview

πŸ“Œ Form Attributes

AttributeDescription
actionWhere to send the form data.
methodHTTP method to use (GET or POST).
enctypeEncoding type (e.g. multipart/form-data for files).
autocompleteEnable or disable browser autocomplete.
targetSpecifies where to display the response (e.g. _blank).

🧩 Input Attributes

AttributeDescription
typeDefines the input type (text, email, password, etc.).
nameUsed to identify the input value on form submission.
requiredMakes the field mandatory to fill.
placeholderShows a hint inside the input field.
readonlyMakes the input non-editable.

🧠 Test Your Knowledge

3 Questions

Progress: 0 / 3
Keep Going!HTML Iframes