I\'ve come across a few examples recently that do things like:
- Full Name:
-
Sometimes, a definition list simply presents the information in the way that's desired, whilst a table does not. Personally, I would probably not use a definition list for a form, unless it suits the style of the site.
I guess it's up to you to determine the semantics, but in my opinion:
Rather than a definition list, form-related properties should be used.
<form>
<label for="fullname">Full Name:</label>
<input type="text" name="fullname" id="fullname">
<label for="email">Email Address:</label>
<input type="text" name="email" id="email">
</form>
The "for" attribute in the <label> tag should reference the "id" attribute of a <input> tag. Note that when labels are associated with fields, clicking the label will put the associated field in focus.
You can also use tags like <fieldset> to cluster sections of a form together and <legend> to caption a fieldset.
Using dl
dt
,dd
for forms is just another way to structure your forms, along with ul
li
, div
and table
. You can always put a label
into dt
. This way you keep the form specific element label
in place.
<form action="/login" method="post">
<dl>
<dt><label for="login">Login</label></dt>
<dd><input type="text" name="login" id="login"/></dd>
<dt><label for="password">Password</label></dt>
<dd><input type="password" name="password" id="password"/></dd>
<dd><input type="submit" value="Add"/></dd>
</dl>
</form>
This is a subset of the issue of semantics vs formatting. A definition list says what they are, a list of related key/value attributes, but does not say how to display it. A table says more about layout and how to display the data then what the data inside is. It limits how the list can be formatted both by overspecifying the format and by underspecifying what it is.
HTML, historically, has mixed up semantics with formatting. Font tags and tables being the worst examples. The move to CSS for the formatting and the stripping of a lot of the pure formatting tags out of XHTML restores, somewhat, the separation of meaning from formatting. By separating formatting into CSS you can display the same HTML in many different ways reformatting it for a wide browser, a small mobile browser, printing, plain text, etc...
For enlightenment, visit the CSS Zen Garden.
In this case, labels and inputs are your semantic meaning and they stand on their own.
Imagine you had to read the web page, out load, to a blind person. You wouldn't say "Okay, I have a list of definitions here. The first term is 'name'." Instead, you'd probably say "Okay we have a form here and it looks like the there's a set of fields, the first input is labeled 'name'."
This is why the semantic web is important. It allows the content of the page to represent itself accurately to both humans and technology. For example, there are many browser plugins that help people quickly fill out web forms with their standard information (name, phone number, etc). These rarely work well if inputs don't have associated labels.
Hope that helps.
Table List Data will be like this:
<table>
<tr>
<td class="title">Name: </td>
<td class="text">John Don</td>
</tr>
<tr>
<td class="title">Age: </td>
<td class="text">23</td>
</tr>
<tr>
<td class="title">Gender: </td>
<td class="text">Male</td>
</tr>
<tr>
<td class="title">Day of Birth:</td>
<td class="text">12th May 1986</td>
</tr>
</table>
And you can use DL, DT, DD Tags List Data like this:
<dl>
<dt>Name: </dt>
<dd>John Don</dd>
<dt>Age: </dt>
<dd>23</dd>
<dt>Gender: </dt>
<dd>Male</dd>
<dt>Day of Birth:</dt>
<dd>12th May 1986</dd>
</dl>