<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ReadyState4 &#187; XHTML</title>
	<atom:link href="http://readystate4.com/category/xhtml/feed/" rel="self" type="application/rss+xml" />
	<link>http://readystate4.com</link>
	<description>JavaScript, Web Development, Ruby, and Technology.</description>
	<lastBuildDate>Fri, 04 Jun 2010 19:42:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Don&#8217;t forget the &#8220;for&#8221; attribute in your HTML form labels</title>
		<link>http://readystate4.com/2008/04/03/dont-forget-the-for-attribute-in-your-html-form-labels/</link>
		<comments>http://readystate4.com/2008/04/03/dont-forget-the-for-attribute-in-your-html-form-labels/#comments</comments>
		<pubDate>Thu, 03 Apr 2008 15:54:07 +0000</pubDate>
		<dc:creator>Mauvis</dc:creator>
				<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://readystate4.com/2008/04/03/dont-forget-the-for-attribute-in-your-html-form-labels/</guid>
		<description><![CDATA[Many developers know that a label is a good element to use inside forms. They help associate text with inputs and aid in accessibility for screen readers and such. For most modern browsers, a proper label when clicked on will also conveniently focus on the input it&#8217;s associated with. However, if your label looks like [...]]]></description>
			<content:encoded><![CDATA[<p>Many developers know that a label is a good element to use inside forms. They help associate text with inputs and aid in accessibility for screen readers and such. For most modern browsers, a proper label when clicked on will also conveniently focus on the input it&#8217;s associated with. However, if your label looks like this, it&#8217;s incorrect:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
     <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span>&gt;</span>Email:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
     <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;email&quot;</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;email&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></div></div>

<p>The browser (and assisting devices) may not be smart enough to associate the label by proximity. You should always explicitly target the element using the the label&#8217;s <code>for</code> property:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
     <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;email&quot;</span>&gt;</span>Email:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
     <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;email&quot;</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;email&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></div></div>

<p>In the forms below, email1 is using an input without the <code>for</code> attribute and email2 is. Try clicking on the labels to see if it makes a difference in your browser.</p>
<form><label>Email1:</label></p>
<input id="email" size="30" name="email" type="text" /> </form>
<form> </form>
<form><label for="email2">Email2:</label></p>
<input id="email2" size="30" name="email2" type="text" /></form>
]]></content:encoded>
			<wfw:commentRss>http://readystate4.com/2008/04/03/dont-forget-the-for-attribute-in-your-html-form-labels/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
