3.9 KiB
3.9 KiB
id | title | challengeType | videoUrl |
---|---|---|---|
587d778a367417b2b2512aa6 | Improve Form Field Accessibility with the label Element | 0 | https://scrimba.com/c/cGJMMAN |
Description
label
tag wraps the text for a specific form control item, usually the name or label for a choice. This ties meaning to the item and makes the form more readable. The for
attribute on a label
tag explicitly associates that label
with the form control and is used by screen readers.
You learned about radio buttons and their labels in a lesson in the Basic HTML section. In that lesson, we wrapped the radio button input element inside a label
element along with the label text in order to make the text clickable. Another way to achieve this is by using the for
attribute as explained in this lesson.
The value of the for
attribute must be the same as the value of the id
attribute of the form control. Here's an example:
<form>
<label for="name">Name:</label>
<input type="text" id="name" name="name">
</form>
Instructions
for
attribute on the email label
that matches the id
on its input
field.
Tests
tests:
- text: Your code should have a <code>for</code> attribute on the <code>label</code> tag that is not empty.
testString: assert($('label').attr('for'), 'Your code should have a <code>for</code> attribute on the <code>label</code> tag that is not empty.');
- text: Your <code>for</code> attribute value should match the <code>id</code> value on the email <code>input</code>.
testString: assert($('label').attr('for') == 'email', 'Your <code>for</code> attribute value should match the <code>id</code> value on the email <code>input</code>.');
Challenge Seed
<body>
<header>
<h1>Deep Thoughts with Master Camper Cat</h1>
</header>
<section>
<form>
<p>Sign up to receive Camper Cat's blog posts by email here!</p>
<label>Email:</label>
<input type="text" id="email" name="email">
<input type="submit" name="submit" value="Submit">
</form>
</section>
<article>
<h2>The Garfield Files: Lasagna as Training Fuel?</h2>
<p>The internet is littered with varying opinions on nutritional paradigms, from catnip paleo to hairball cleanses. But let's turn our attention to an often overlooked fitness fuel, and examine the protein-carb-NOM trifecta that is lasagna...</p>
</article>
<img src="samuraiSwords.jpeg" alt="">
<article>
<h2>Defeating your Foe: the Red Dot is Ours!</h2>
<p>Felines the world over have been waging war on the most persistent of foes. This red nemesis combines both cunning stealth and lightening speed. But chin up, fellow fighters, our time for victory may soon be near...</p>
</article>
<img src="samuraiSwords.jpeg" alt="">
<article>
<h2>Is Chuck Norris a Cat Person?</h2>
<p>Chuck Norris is widely regarded as the premier martial artist on the planet, and it's a complete coincidence anyone who disagrees with this fact mysteriously disappears soon after. But the real question is, is he a cat person?...</p>
</article>
<footer>© 2018 Camper Cat</footer>
</body>
Solution
// solution required