Quest 1 β’ Lesson 5
π Forms & Inputs
HTML forms collect user input β search boxes, login fields, contact messages. The <form> element wraps all input elements, and <input> defines the field type.
"Forms are the bridge between users and your website. They enable interaction, searches, and data submission."
form.html
<form action="/submit" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<button type="submit">Send</button>
</form>
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<button type="submit">Send</button>
</form>
π§ Form Elements Explained
<form>β container for inputs. Attributes:action(where data goes),method(GET or POST).<label>β text description linked to an input viaforattribute (improves accessibility).<input>β the field itself. Thetypeattribute defines behaviour (text, email, password, etc.).<button>β submits the form when clicked.
ποΈ Common Input Types
text
password
number
π Radio Buttons & Checkboxes
Radio (select one):
Checkbox (select multiple):
<input type="radio" name="gender" value="male"> Male
π Live Demo: Contact Form
Fill out the form and click "Submit" β see the data in the console (rightβclick β Inspect β Console).
π JavaScript used (only for demo)
function handleFormSubmit(event) {
event.preventDefault();
const formData = new FormData(event.target);
console.log("Form data:", Object.fromEntries(formData));
document.getElementById('formFeedback').classList.remove('hidden');
}
β¨ Challenge: Build a Survey Form
Create a simple survey with:
- Text input for name
- Radio buttons for experience (Beginner / Intermediate / Advanced)
- Checkbox for interests (HTML, Python, AI)
- Submit button
β€οΈ Support Free Education
This course is 100% free. If it helps you, consider buying me a coffee.
β Buy Me a Coffeeβ‘οΈ Ready for more?
Next lesson: Semantic HTML & Accessibility β build better websites.
Continue to Lesson 1.6 β(Coming soon β check back or buy Pro Pack for instant access)