Label not associated to input
Using the built in Chrome Lighthouse to run accessibility audit on a WP site showed the signup field as being invalid due to no associated label. I've run into this before and I can't understand why it doesn't think it's associated. I can get it to pass by adding an aria-label
tag to the input
directly but I shouldn't have to do that.
Here is a code snippet that is created from Subscribe2
<label for="s2email">Your email:</label>
<br>
<input type="text" name="email" id="s2email" value="Enter email address..." size="20" onfocus="if (this.value === 'Enter email address...') {this.value = '';}" onblur="if (this.value === '') {this.value = 'Enter email address...';}">
Can be found here: https://blog.collaborative.org/
html accessibility html-form html-validation lighthouse
|
show 1 more comment
Using the built in Chrome Lighthouse to run accessibility audit on a WP site showed the signup field as being invalid due to no associated label. I've run into this before and I can't understand why it doesn't think it's associated. I can get it to pass by adding an aria-label
tag to the input
directly but I shouldn't have to do that.
Here is a code snippet that is created from Subscribe2
<label for="s2email">Your email:</label>
<br>
<input type="text" name="email" id="s2email" value="Enter email address..." size="20" onfocus="if (this.value === 'Enter email address...') {this.value = '';}" onblur="if (this.value === '') {this.value = 'Enter email address...';}">
Can be found here: https://blog.collaborative.org/
html accessibility html-form html-validation lighthouse
Something is missing from your example. If I copy/paste your sample into a simple page, it passes lighthouse (and axe). The <label> correctly points to the <input>. I usually see problems when the <input> has a NAME attribute but not an ID attribute. That is, the <label> points to "s3email" but the <input> hasname="s2email"
(which is for javascript) and doesn't haveid="s2email"
.
– slugolicious
Nov 28 '18 at 20:05
Note also that youronfocus
is pointing to a string instead of a function. That's another hint that you might have typed the code sample instead of copy/pasting the original code that has the problem. I'm assuming you don't really have anon
handler pointing to a string.
– slugolicious
Nov 28 '18 at 20:07
The for/id relationship looks correct here. Can we see the actual page, to look at the whole context? Or, can you provide the exact report that the tool provided?
– andrewmacpherson
Nov 28 '18 at 20:09
Are the IDs unique? If there are two inputs with the same ID that could cause this.
– andrewmacpherson
Nov 28 '18 at 20:13
Sure, I had stripped it apart a little to simplify it. Will update OP.
– Travis Johnston
Nov 28 '18 at 20:14
|
show 1 more comment
Using the built in Chrome Lighthouse to run accessibility audit on a WP site showed the signup field as being invalid due to no associated label. I've run into this before and I can't understand why it doesn't think it's associated. I can get it to pass by adding an aria-label
tag to the input
directly but I shouldn't have to do that.
Here is a code snippet that is created from Subscribe2
<label for="s2email">Your email:</label>
<br>
<input type="text" name="email" id="s2email" value="Enter email address..." size="20" onfocus="if (this.value === 'Enter email address...') {this.value = '';}" onblur="if (this.value === '') {this.value = 'Enter email address...';}">
Can be found here: https://blog.collaborative.org/
html accessibility html-form html-validation lighthouse
Using the built in Chrome Lighthouse to run accessibility audit on a WP site showed the signup field as being invalid due to no associated label. I've run into this before and I can't understand why it doesn't think it's associated. I can get it to pass by adding an aria-label
tag to the input
directly but I shouldn't have to do that.
Here is a code snippet that is created from Subscribe2
<label for="s2email">Your email:</label>
<br>
<input type="text" name="email" id="s2email" value="Enter email address..." size="20" onfocus="if (this.value === 'Enter email address...') {this.value = '';}" onblur="if (this.value === '') {this.value = 'Enter email address...';}">
Can be found here: https://blog.collaborative.org/
html accessibility html-form html-validation lighthouse
html accessibility html-form html-validation lighthouse
edited yesterday
Jaap
395613
395613
asked Nov 28 '18 at 18:46
Travis JohnstonTravis Johnston
19110
19110
Something is missing from your example. If I copy/paste your sample into a simple page, it passes lighthouse (and axe). The <label> correctly points to the <input>. I usually see problems when the <input> has a NAME attribute but not an ID attribute. That is, the <label> points to "s3email" but the <input> hasname="s2email"
(which is for javascript) and doesn't haveid="s2email"
.
– slugolicious
Nov 28 '18 at 20:05
Note also that youronfocus
is pointing to a string instead of a function. That's another hint that you might have typed the code sample instead of copy/pasting the original code that has the problem. I'm assuming you don't really have anon
handler pointing to a string.
– slugolicious
Nov 28 '18 at 20:07
The for/id relationship looks correct here. Can we see the actual page, to look at the whole context? Or, can you provide the exact report that the tool provided?
– andrewmacpherson
Nov 28 '18 at 20:09
Are the IDs unique? If there are two inputs with the same ID that could cause this.
– andrewmacpherson
Nov 28 '18 at 20:13
Sure, I had stripped it apart a little to simplify it. Will update OP.
– Travis Johnston
Nov 28 '18 at 20:14
|
show 1 more comment
Something is missing from your example. If I copy/paste your sample into a simple page, it passes lighthouse (and axe). The <label> correctly points to the <input>. I usually see problems when the <input> has a NAME attribute but not an ID attribute. That is, the <label> points to "s3email" but the <input> hasname="s2email"
(which is for javascript) and doesn't haveid="s2email"
.
– slugolicious
Nov 28 '18 at 20:05
Note also that youronfocus
is pointing to a string instead of a function. That's another hint that you might have typed the code sample instead of copy/pasting the original code that has the problem. I'm assuming you don't really have anon
handler pointing to a string.
– slugolicious
Nov 28 '18 at 20:07
The for/id relationship looks correct here. Can we see the actual page, to look at the whole context? Or, can you provide the exact report that the tool provided?
– andrewmacpherson
Nov 28 '18 at 20:09
Are the IDs unique? If there are two inputs with the same ID that could cause this.
– andrewmacpherson
Nov 28 '18 at 20:13
Sure, I had stripped it apart a little to simplify it. Will update OP.
– Travis Johnston
Nov 28 '18 at 20:14
Something is missing from your example. If I copy/paste your sample into a simple page, it passes lighthouse (and axe). The <label> correctly points to the <input>. I usually see problems when the <input> has a NAME attribute but not an ID attribute. That is, the <label> points to "s3email" but the <input> has
name="s2email"
(which is for javascript) and doesn't have id="s2email"
.– slugolicious
Nov 28 '18 at 20:05
Something is missing from your example. If I copy/paste your sample into a simple page, it passes lighthouse (and axe). The <label> correctly points to the <input>. I usually see problems when the <input> has a NAME attribute but not an ID attribute. That is, the <label> points to "s3email" but the <input> has
name="s2email"
(which is for javascript) and doesn't have id="s2email"
.– slugolicious
Nov 28 '18 at 20:05
Note also that your
onfocus
is pointing to a string instead of a function. That's another hint that you might have typed the code sample instead of copy/pasting the original code that has the problem. I'm assuming you don't really have an on
handler pointing to a string.– slugolicious
Nov 28 '18 at 20:07
Note also that your
onfocus
is pointing to a string instead of a function. That's another hint that you might have typed the code sample instead of copy/pasting the original code that has the problem. I'm assuming you don't really have an on
handler pointing to a string.– slugolicious
Nov 28 '18 at 20:07
The for/id relationship looks correct here. Can we see the actual page, to look at the whole context? Or, can you provide the exact report that the tool provided?
– andrewmacpherson
Nov 28 '18 at 20:09
The for/id relationship looks correct here. Can we see the actual page, to look at the whole context? Or, can you provide the exact report that the tool provided?
– andrewmacpherson
Nov 28 '18 at 20:09
Are the IDs unique? If there are two inputs with the same ID that could cause this.
– andrewmacpherson
Nov 28 '18 at 20:13
Are the IDs unique? If there are two inputs with the same ID that could cause this.
– andrewmacpherson
Nov 28 '18 at 20:13
Sure, I had stripped it apart a little to simplify it. Will update OP.
– Travis Johnston
Nov 28 '18 at 20:14
Sure, I had stripped it apart a little to simplify it. Will update OP.
– Travis Johnston
Nov 28 '18 at 20:14
|
show 1 more comment
1 Answer
1
active
oldest
votes
When you look at the code sample in isolation, it looks fine: it has a label
explicitly associated with the input
element using the for
and id
attributes.
However, when you inspect the site, it looks different: due to the style rule .s2_form_widget label { display: none; }
the label is invisible. (You can see this when you use the Inspector in Firefox, move to the label in the DOM tree and check the associated styles.)
Note that display: none
does not only hide the label visually but also for screen readers. As a result, the input element has no label from the point of view of a screen reader or another assistive technology and fails the requirement that form controls need explicit labels. (As an alternative, you might try hiding the label off-screen with a negative margin.)
Ahh that makes sense! I'll adjust that and test.
– Travis Johnston
Nov 29 '18 at 14:10
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53526123%2flabel-not-associated-to-input%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
When you look at the code sample in isolation, it looks fine: it has a label
explicitly associated with the input
element using the for
and id
attributes.
However, when you inspect the site, it looks different: due to the style rule .s2_form_widget label { display: none; }
the label is invisible. (You can see this when you use the Inspector in Firefox, move to the label in the DOM tree and check the associated styles.)
Note that display: none
does not only hide the label visually but also for screen readers. As a result, the input element has no label from the point of view of a screen reader or another assistive technology and fails the requirement that form controls need explicit labels. (As an alternative, you might try hiding the label off-screen with a negative margin.)
Ahh that makes sense! I'll adjust that and test.
– Travis Johnston
Nov 29 '18 at 14:10
add a comment |
When you look at the code sample in isolation, it looks fine: it has a label
explicitly associated with the input
element using the for
and id
attributes.
However, when you inspect the site, it looks different: due to the style rule .s2_form_widget label { display: none; }
the label is invisible. (You can see this when you use the Inspector in Firefox, move to the label in the DOM tree and check the associated styles.)
Note that display: none
does not only hide the label visually but also for screen readers. As a result, the input element has no label from the point of view of a screen reader or another assistive technology and fails the requirement that form controls need explicit labels. (As an alternative, you might try hiding the label off-screen with a negative margin.)
Ahh that makes sense! I'll adjust that and test.
– Travis Johnston
Nov 29 '18 at 14:10
add a comment |
When you look at the code sample in isolation, it looks fine: it has a label
explicitly associated with the input
element using the for
and id
attributes.
However, when you inspect the site, it looks different: due to the style rule .s2_form_widget label { display: none; }
the label is invisible. (You can see this when you use the Inspector in Firefox, move to the label in the DOM tree and check the associated styles.)
Note that display: none
does not only hide the label visually but also for screen readers. As a result, the input element has no label from the point of view of a screen reader or another assistive technology and fails the requirement that form controls need explicit labels. (As an alternative, you might try hiding the label off-screen with a negative margin.)
When you look at the code sample in isolation, it looks fine: it has a label
explicitly associated with the input
element using the for
and id
attributes.
However, when you inspect the site, it looks different: due to the style rule .s2_form_widget label { display: none; }
the label is invisible. (You can see this when you use the Inspector in Firefox, move to the label in the DOM tree and check the associated styles.)
Note that display: none
does not only hide the label visually but also for screen readers. As a result, the input element has no label from the point of view of a screen reader or another assistive technology and fails the requirement that form controls need explicit labels. (As an alternative, you might try hiding the label off-screen with a negative margin.)
answered Nov 29 '18 at 14:05
Christophe StrobbeChristophe Strobbe
1,38011023
1,38011023
Ahh that makes sense! I'll adjust that and test.
– Travis Johnston
Nov 29 '18 at 14:10
add a comment |
Ahh that makes sense! I'll adjust that and test.
– Travis Johnston
Nov 29 '18 at 14:10
Ahh that makes sense! I'll adjust that and test.
– Travis Johnston
Nov 29 '18 at 14:10
Ahh that makes sense! I'll adjust that and test.
– Travis Johnston
Nov 29 '18 at 14:10
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53526123%2flabel-not-associated-to-input%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Something is missing from your example. If I copy/paste your sample into a simple page, it passes lighthouse (and axe). The <label> correctly points to the <input>. I usually see problems when the <input> has a NAME attribute but not an ID attribute. That is, the <label> points to "s3email" but the <input> has
name="s2email"
(which is for javascript) and doesn't haveid="s2email"
.– slugolicious
Nov 28 '18 at 20:05
Note also that your
onfocus
is pointing to a string instead of a function. That's another hint that you might have typed the code sample instead of copy/pasting the original code that has the problem. I'm assuming you don't really have anon
handler pointing to a string.– slugolicious
Nov 28 '18 at 20:07
The for/id relationship looks correct here. Can we see the actual page, to look at the whole context? Or, can you provide the exact report that the tool provided?
– andrewmacpherson
Nov 28 '18 at 20:09
Are the IDs unique? If there are two inputs with the same ID that could cause this.
– andrewmacpherson
Nov 28 '18 at 20:13
Sure, I had stripped it apart a little to simplify it. Will update OP.
– Travis Johnston
Nov 28 '18 at 20:14