📖 Scenario: You are building a simple feedback form for a website. Users will type their comments or suggestions in a box.
🎯 Goal: Build a basic HTML form that includes a <textarea> element where users can enter their feedback.
📋 What You'll Learn
Use semantic HTML5 elements
Include a <textarea> with a label for accessibility
Set the rows and cols attributes on the textarea
Add a submit button
Ensure the form is responsive and accessible
💡 Why This Matters
🌍 Real World
Feedback forms are common on websites to collect user opinions, bug reports, or suggestions.
💼 Career
Knowing how to build accessible and semantic forms is essential for front-end web development roles.
Progress0 / 4 steps
1
Create the basic HTML form structure
Write the HTML code to create a <form> element with a <label> for feedback and a <textarea> with id="feedback". Set the rows attribute to 4 and the cols attribute to 50.
HTML
Hint
Use a <label> with a for attribute matching the id of the <textarea>.
2
Add a submit button to the form
Add a <button> element inside the <form> with type="submit" and the text Send Feedback.
HTML
Hint
The submit button should be inside the form and have type="submit".
3
Add accessibility features to the textarea
Add the aria-label="Feedback text area" attribute to the <textarea> element to improve accessibility.
HTML
Hint
The aria-label attribute helps screen readers describe the textarea.
4
Wrap the form in a semantic <main> element and add a heading
Wrap the entire <form> inside a <main> element. Above the form, add an <h1> heading with the text Feedback Form.
HTML
Hint
The <main> element is used for the main content. The heading helps users understand the page purpose.
Practice
(1/5)
1. What is the main purpose of the <textarea> tag in HTML?
easy
A. To display a single line of text that cannot be edited.
B. To add a button that submits a form.
C. To create a multi-line text input box for users to type in.
D. To insert an image into the webpage.
Solution
Step 1: Understand the <textarea> tag function
The <textarea> tag is designed to allow users to enter multiple lines of text, unlike <input> which is usually single line.
Step 2: Compare options with the tag's purpose
Options A, C, and D describe other HTML elements or functions, not multi-line text input.
Final Answer:
To create a multi-line text input box for users to type in. -> Option C
Quick Check:
Textarea = multi-line input [OK]
Hint: Textarea means multi-line text box for typing [OK]
Common Mistakes:
Confusing <textarea> with <input> for single line input
Thinking <textarea> is for buttons or images
Assuming <textarea> is read-only
2. Which of the following is the correct way to set the size of a <textarea> using HTML attributes?
easy
A. <textarea rows='4' cols='50'></textarea>
B. <textarea length='50' height='4'></textarea>
C. <textarea size='large'></textarea>
D. <textarea width='300' height='100'></textarea>
Solution
Step 1: Recall valid <textarea> size attributes
The rows and cols attributes define the visible height and width in lines and characters.
Step 2: Check each option for correct attribute usage
<textarea rows='4' cols='50'></textarea> uses rows and cols correctly. Options A, B, and C use invalid or non-existent attributes.
Final Answer:
<textarea rows='4' cols='50'></textarea> -> Option A
Quick Check:
Rows and cols set size [OK]
Hint: Use rows and cols to size textarea in HTML [OK]
Common Mistakes:
Using width and height attributes directly on textarea
Using non-standard attributes like size or length
Confusing CSS properties with HTML attributes
3. What will be displayed in the browser for this HTML snippet?