What is the purpose of the <form> element in HTML?
The <form> element groups input fields and controls to collect user data and send it to a server when submitted.
Click to reveal answer
beginner
What attribute of the <form> element specifies where the form data is sent?
The action attribute defines the URL where the form data will be sent after submission.
Click to reveal answer
beginner
What does the method attribute of the <form> element do?
The method attribute specifies how to send form data: GET appends data to the URL, POST sends data inside the request body.
Click to reveal answer
beginner
What happens when a user clicks a submit button inside a form?
Clicking a submit button sends the form data to the URL in the action attribute using the specified method. The browser then loads the response page.
Click to reveal answer
beginner
Why is it important to use labels with form inputs?
Labels improve accessibility by linking text descriptions to inputs, helping screen readers and making the form easier to use.
Click to reveal answer
Which attribute in a form specifies the URL to send data to?
Aaction
Bmethod
Ctype
Dname
✗ Incorrect
The action attribute tells the browser where to send the form data.
What does the method="POST" do in a form?
ASends data in the URL
BSends data inside the request body
CPrevents form submission
DChanges the form style
✗ Incorrect
POST sends form data inside the request body, keeping it hidden from the URL.
Which element creates a button that submits a form?
A<input type="button">
B<button type="reset">
C<input type="submit">
D<button>
✗ Incorrect
creates a button that sends the form data when clicked.
Why should you use a <label> with form inputs?
ATo add color
BTo disable inputs
CTo make inputs bigger
DTo improve accessibility
✗ Incorrect
Labels help screen readers and users understand what each input is for.
What happens if a form has no action attribute?
AForm data is sent to the current page URL
BForm cannot be submitted
CForm data is sent to Google
DForm data is lost
✗ Incorrect
Without an action, the form submits to the same page URL by default.
Explain how a basic HTML form sends data to a server.
Think about what happens when you fill a form and press submit.
You got /5 concepts.
Describe why accessibility is important in form design and how labels help.
Imagine someone who cannot see well using your form.
You got /4 concepts.
Practice
(1/5)
1. What does the action attribute in an HTML form specify?
easy
A. The type of input fields inside the form
B. The style of the form on the page
C. The method used to send the form data
D. The URL where the form data is sent after submission
Solution
Step 1: Understand the role of action attribute
The action attribute tells the browser where to send the form data when the user submits the form.
Step 2: Differentiate from other attributes
The method attribute controls how data is sent, not where. Styling and input types are unrelated to action.
Final Answer:
The URL where the form data is sent after submission -> Option D
Quick Check:
action = URL destination [OK]
Hint: Remember: action = destination URL for form data [OK]
Common Mistakes:
Confusing action with method
Thinking action controls form style
Assuming action sets input types
2. Which of the following is the correct way to start a form that sends data using POST method to '/submit' URL?
easy
A.
B.
C.
D.
Solution
Step 1: Check attribute order and values
Both action and method attributes are needed. The method should be 'post' and action should be '/submit'. The order of attributes does not affect correctness.
Step 2: Validate each option
The <form method='post' action='submit'> has incorrect action (missing leading '/'). The <form action='/submit' method='post'> uses correct attribute names and values. The one with method='get' uses wrong method for POST. The one with method='submit' uses invalid method and action values.
Final Answer:
<form action='/submit' method='post'> -> Option B
Quick Check:
Correct syntax with POST method and action URL [OK]
Hint: Use for POST forms [OK]
Common Mistakes:
Using 'submit' as method instead of 'post' or 'get'
The form uses correct action and method. The submit button has a value and defaults to type='submit'.
Step 2: Identify accessibility issue
The input field lacks a <label> element, which helps screen readers and improves usability.
Final Answer:
Missing <label> for the input field -> Option A
Quick Check:
Labels improve accessibility [OK]
Hint: Always add <label> for inputs to help all users [OK]
Common Mistakes:
Thinking submit button needs explicit type
Assuming method='post' is wrong
Believing action URL must be absolute
5. You want to create a form that sends user feedback to '/feedback' using POST. The form should have a text area labeled 'Comments' and a submit button labeled 'Send Feedback'. Which code snippet correctly implements this with accessibility and submission basics?
hard
A. \n Comments\n \n Send Feedback\n
B. \n \n \n
C. \n Comments\n \n Send Feedback\n
D. \n Comments\n \n \n
Solution
Step 1: Check form action and method
The form must send data to '/feedback' using POST method. <form action='/feedback' method='post'>\n <label for='comments'>Comments</label>\n <textarea id='comments' name='comments'></textarea>\n <button type='submit'>Send Feedback</button>\n</form> and B have method='post', but B lacks label.
Step 2: Verify accessibility and button labeling
<form action='/feedback' method='post'>\n <label for='comments'>Comments</label>\n <textarea id='comments' name='comments'></textarea>\n <button type='submit'>Send Feedback</button>\n</form> uses a <label> linked to the textarea with for and id, improving accessibility. The submit button is a <button> with clear text.
Step 3: Eliminate incorrect options
<form action='/feedback' method='get'>\n <label>Comments</label>\n <textarea id='comments'></textarea>\n <button>Send Feedback</button>\n</form> uses GET method and missing name attribute on textarea, and label is not linked. <form action='/feedback'>\n <label for='comments'>Comments</label>\n <textarea id='comments' name='comments'></textarea>\n <input type='submit' value='Send Feedback'>\n</form> misses method attribute, so defaults to GET.
Final Answer:
code snippet with proper action, method, label, and button -> Option A
Quick Check:
Use POST + label + submit button for accessible form [OK]
Hint: Use label with for/id and method='post' for forms [OK]
Common Mistakes:
Omitting method attribute defaults to GET
Not linking label to input with for and id
Using GET when POST is required
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.