You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Labels on input fields might seem like small details, but they play a crucial role in making forms easier for everyone to use.
11
11
@@ -17,13 +17,17 @@ Screen readers often rely on labels to describe the purpose of input fields. In
17
17
18
18
Here's how to associate a `label` with an `input`:
19
19
20
+
:::interactive_editor
21
+
20
22
```html
21
23
<form>
22
24
<labelfor="name">Your Name</label>
23
25
<inputtype="text"id="name" />
24
26
</form>
25
27
```
26
28
29
+
:::
30
+
27
31
In this example, the `for` attribute of the `label` element is associated with the `id` of the `input` element. This connection allows screen readers to announce the `label` when the `input` is in a focused state, allowing screen reader users to understand the purpose of the `input`.
28
32
29
33
Associating labels with all input fields also benefits SEO. With proper labels, search engines will understand the page content better, leading to a positive impact on the page search rankings.
@@ -70,71 +74,71 @@ Think about how screen readers provide information to users.
70
74
71
75
## --text--
72
76
73
-
How do labels associated with input fields improve keyboard navigation?
77
+
What is the correct way to programmatically associate a label with an input in HTML?
74
78
75
79
## --answers--
76
80
77
-
They enhance the visual appearance of input fields.
81
+
Give both elements the same `name` attribute.
78
82
79
83
### --feedback--
80
84
81
-
Focus on how users move through a form using only the keyboard.
85
+
Review the example in the lesson showing how `for` and `id` are used together.
82
86
83
87
---
84
88
85
-
They allow users to tab through input fields without getting lost.
89
+
Set the label's `for` attribute to match the input's `id`.
86
90
87
91
---
88
92
89
-
They reduce the need for keyboard shortcuts.
93
+
Place the `<label>` immediately after the `<input>` element in the DOM.
90
94
91
95
### --feedback--
92
96
93
-
Focus on how users move through a form using only the keyboard.
97
+
Order alone does not create an association that screen readers can use.
94
98
95
99
---
96
100
97
-
They let input fields accept special characters.
101
+
Use the input's `placeholder` text instead of a label.
98
102
99
103
### --feedback--
100
104
101
-
Focus on how users move through a form using only the keyboard.
105
+
Placeholders are not a replacement for accessible, programmatically associated labels.
102
106
103
107
## --video-solution--
104
108
105
109
2
106
110
107
111
## --text--
108
112
109
-
How do labels associated with input fields help in identifying errors?
113
+
Besides accessibility, what other benefit of associating labels with inputs is mentioned in the lesson?
110
114
111
115
## --answers--
112
116
113
-
They allow input fields to accept longer text.
117
+
It makes the page load significantly faster.
114
118
115
119
### --feedback--
116
120
117
-
Think about how error messages are communicated to users by screen readers.
121
+
Performance is not the benefit discussed in this lesson.
118
122
119
123
---
120
124
121
-
They help screen readers announce the label along with the error message.
125
+
It can help search engines better understand the page content.
122
126
123
127
---
124
128
125
-
They prevent users from submitting forms.
129
+
It allows inputs to accept multiple data types automatically.
126
130
127
131
### --feedback--
128
132
129
-
Think about how error messages are communicated to users by screen readers.
133
+
Data types are determined by the input's `type` attribute, not labels.
130
134
131
135
---
132
136
133
-
They make input fields more colorful.
137
+
It automatically translates labels for international users.
134
138
135
139
### --feedback--
136
140
137
-
Think about how error messages are communicated to users by screen readers.
141
+
Internationalization is outside the scope of what labels provide.
0 commit comments