<?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>Tech Hive &#124; Front End Development, WordPress and Drupal Developer&#187; HTML</title>
	<atom:link href="http://tech-hive.com/topic/front-end/html/feed/" rel="self" type="application/rss+xml" />
	<link>http://tech-hive.com</link>
	<description>Mae Paulino &#124; Web Designer and Front End Developer</description>
	<lastBuildDate>Mon, 01 Aug 2011 05:29:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Using dl for a Semantic Form</title>
		<link>http://tech-hive.com/front-end/html/using-dl-for-a-semantic-form-20100813/</link>
		<comments>http://tech-hive.com/front-end/html/using-dl-for-a-semantic-form-20100813/#comments</comments>
		<pubDate>Thu, 12 Aug 2010 21:00:00 +0000</pubDate>
		<dc:creator>Mae</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[best practices]]></category>
		<category><![CDATA[definition lists]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[semantic form]]></category>

		<guid isPermaLink="false">http://tech-hive.com/?p=168</guid>
		<description><![CDATA[Wufoo&#8217;s login form Semantics in forms are one of the things that needs to be talked about, in my opinion, since they are one of the most important parts of a web site. You create/edit user accounts, create/edit blog posts, submit a comment, gather information from your audience, and lots more through them. However, apart from fieldset, we don&#8217;t really have a semantic way of marking up a pair of form elements. There are different ways in marking up one&#8217;s form: div, p, ul or ol and dl. Because using dl, or definition list, to mark up a form is still unusual even though it&#8217;s not exactly a new idea, I will be talking and boring you, unfortunate people, about it here. Understanding the dl element dl is one of the most overlooked element in HTML since, I assume, people mostly associate it with just definition lists, aka glossary. But &#8230; <a href="http://tech-hive.com/front-end/html/using-dl-for-a-semantic-form-20100813/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p class="alignleft"><img src="http://tech-hive.com/wp-content/uploads/2010/08/form.jpg" alt="" title="Wufoo&#039;s login form" width="300" height="185" class="size-full wp-image-243" /><br />
<a href="http://wufoo.com" class="extra">Wufoo&#8217;s</a> login form</p>
<p>Semantics in forms are one of the things that needs to be talked about, in my opinion, since they are one of the most important parts of a web site. You create/edit user accounts, create/edit blog posts, submit a comment, gather information from your audience, and lots more through them. However, apart from <code>fieldset</code>, we don&#8217;t really have a semantic way of marking up a pair of form elements.</p>
<p>There are different ways in marking up one&#8217;s form: <code>div</code>, <code>p</code>, <code>ul</code> or <code>ol</code> and <code>dl</code>. Because using <code>dl</code>, or definition list, to mark up a form is still unusual even though it&#8217;s <a href="http://www.clagnut.com/blog/241/" title="October 3, 2003 - Form Layout">not exactly</a> <a href="http://www.devarticles.com/c/a/Web-Design-Standards/Web-Forms/2/" title="August 23, 2004 - Web Forms">a new idea</a>, I will be talking and boring you, unfortunate people, about it here.</p>
<h3>Understanding the <code>dl</code> element</h3>
<p><code>dl</code> is one of the most overlooked element in HTML since, I assume, people mostly associate it with just definition lists, aka glossary. But it can be much, much more as was shown by Mike Robinson in his article about <a href="http://html5doctor.com/the-dl-element/">the <code>dl</code> element</a> in HTML5 Doctor. The HTML5 draft describes definition list as:</p>
<blockquote cite="http://www.w3.org/TR/html5/grouping-content.html#the-dl-element"><p>The <code>dl</code> element represents an association list consisting of zero or more name-value groups (a description list). Each group must consist of one or more names (<code>dt</code> elements) followed by one or more values (<code>dd</code> elements). </p>
<p><cite><a href="http://www.w3.org/TR/html5/grouping-content.html#the-dl-element">HTML5 Working Draft: The <code>dl</code> element</a></cite></p></blockquote>
<p>The key to why <code>dl</code> is the mark up that makes most sense (at least to me) is the <strong>name-value groups</strong> phrase. Form elements are all about pairing as you have the label which is the name and the corresponding value which is the <code>input</code> or <code>textarea</code> or <code>select</code>.</p>
<p><span id="more-168"></span></p>
<p>Using <code>dl</code>, your code is going to look something like this:</p>
<pre><code>&lt;form action=""&gt;
  &lt;dl&gt;
    &lt;dt&gt;&lt;label for="input-value"&gt;Label Name&lt;/label&gt;&lt;/dt&gt;
    &lt;dd&gt;&lt;input type="text" name="input-value" id="input-value" size="32" /&gt;&lt;/dd&gt;
  &lt;/dl&gt;
&lt;/form&gt;</code></pre>
<h3>Pros</h3>
<p>Aside from your code being semantic, using definition lists for forms will enable you to have a correctly styled form element by default since both <code>dt</code> (definition term aka term) and <code>dd</code> (definition aka value) are block elements. <code>dl</code> also lets you mark checkboxes up with more sense like so:</p>
<pre><code>&lt;dt&gt;Select one or more option:&lt;/dt&gt;
&lt;dd&gt;
  &lt;label&gt;
    &lt;input type="checkbox" name="value-1" id="value-1" /&gt;
  &lt;/label&gt;
&lt;/dd&gt;
&lt;dd&gt;
  &lt;label&gt;
    &lt;input type="checkbox" name="value-2" id="value-2" /&gt;
  &lt;/label&gt;
&lt;/dd&gt;
&lt;dd&gt;
  &lt;label&gt;
    &lt;input type="checkbox" name="value-3" id="value-3" /&gt;
  &lt;/label&gt;
&lt;/dd&gt;</code></pre>
<p>I have to admit that I&#8217;m stumped checkboxes and radio boxes. There are times when it makes sense to put the option heading in a <code>legend</code>, but you can&#8217;t always put them in a separate <code>fieldset</code>! Using a heading element makes even less sense. Most of the time, I just use <code>label</code> even though it&#8217;s not really linked to anything. Well, <code>p</code> works, too.</p>
<h3>Cons</h3>
<p>Like everything else, using <code>dl</code> isn&#8217;t really foolproof:</p>
<ul>
<li><code>dt</code> and <code>dd</code> are separate elements which makes it harder for you to clear them in case you&#8217;ve decided to float them and have multiple values. This scenario is easier for <code>div</code>, <code>li</code> and <code>p</code> because they act as a wrapper to the label-input pair. You can fix this by clearing your <code>dt</code>.</li>
<li>You&#8217;ll encounter a version of the above mentioned problem when you have an empty value in a pair. You can either put a space (<code>&#038;nbsp ;</code>) or min-height. I&#8217;m thinking that min-height is the better solution between the two, though.</li>
<li>An IE 6 problem: when you add a block element within <code>dl</code> and its child elements, IE6 escapes the definition list so that the block element is outside it. There&#8217;s still a workaround like, instead of <code>p</code>, you can use <code>span</code> instead, which sort of defeats the purpose of what we&#8217;re trying to do. Ken, a co-worker of mine assured me that that problem doesn&#8217;t exist in IE 7, which is a sigh of relief.</li>
</ul>
<p>Personally, I think the pros outweighs the various CSS issues you might encounter in the process. Nothing makes you feel better than being able to solve a CSS problem, which is probably why I miss IE 6 sometimes (isn&#8217;t that sad?). :( </p>
<p>How do you mark up your form? Do you think you&#8217;ll try and switch to <code>dl</code> one of these days?</p>
<div class="more_reading">
<h3>Further reading</h3>
<p>Still not bored to death? :P </p>
<ul>
<li><a href="http://www.w3.org/TR/html5/forms.html#forms">HTML5 Working Drafts: Forms</a></li>
<li><a href="http://reference.sitepoint.com/html/elements-form">List of Form Elements in SitePoint</a></li>
<li><a href="http://web.enavu.com/snippets/web-forms-semantic-mark-up-in-our-forms-part-2/">Semantic Mark Up in our Forms</a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://tech-hive.com/front-end/html/using-dl-for-a-semantic-form-20100813/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

