📖 Scenario: You want to create a simple contact form on a website so visitors can send their name and message.
🎯 Goal: Build a basic HTML form with fields for name and message, and a submit button.
📋 What You'll Learn
Use semantic HTML form elements
Include labels for accessibility
Add a text input for the visitor's name
Add a textarea for the visitor's message
Add a submit button
💡 Why This Matters
🌍 Real World
Contact forms are common on websites to let visitors send messages or inquiries easily.
💼 Career
Knowing how to build accessible and semantic forms is essential for web developers working on user interfaces.
Progress0 / 4 steps
1
Create the HTML form skeleton
Write the opening <form> tag with action="#" and method="post", then add the closing </form> tag.
HTML
Hint
The form tag needs an action attribute and a method attribute.
2
Add a label and text input for the visitor's name
Inside the <form>, add a <label> with for="name" and text "Name:". Then add an <input> with type="text", id="name", and name="name".
HTML
Hint
Labels help screen readers and link to inputs using the for attribute matching the input's id.
3
Add a label and textarea for the visitor's message
Inside the <form>, after the name input, add a <label> with for="message" and text "Message:". Then add a <textarea> with id="message" and name="message".
HTML
Hint
The textarea lets visitors write longer messages. It also needs a label for accessibility.
4
Add a submit button to the form
Inside the <form>, after the textarea, add a <button> with type="submit" and text "Send".
HTML
Hint
The submit button sends the form data to the server or page specified in the form's action.
Practice
(1/5)
1. What is the main purpose of the <form> element in HTML?
easy
A. To style text content
B. To display images on a webpage
C. To create a navigation menu
D. To collect user input and send it to a server
Solution
Step 1: Understand the role of the <form> tag
The <form> element groups input fields and buttons to collect user data.
Step 2: Identify the purpose of forms
Forms send collected data to a server for processing, like login or signup.
Final Answer:
To collect user input and send it to a server -> Option D
Quick Check:
Form = collect and send data [OK]
Hint: Forms wrap inputs to send data to servers [OK]
Common Mistakes:
Confusing forms with layout elements
Thinking forms style content
Assuming forms display images
2. Which attribute in the <form> tag specifies where the form data is sent?
easy
A. type
B. method
C. action
D. name
Solution
Step 1: Identify the purpose of the 'action' attribute
The 'action' attribute defines the URL where form data is sent after submission.
Step 2: Differentiate from other attributes
'method' defines how data is sent (GET or POST), 'type' and 'name' are not for destination.