What html markups to use for displaying label/value data?
I think the most semantically correct would be <dl>
, <dt>
and <dd>
, since what you're displaying are effectively definitions of first name, age and e-mail.
<dl>
<dt>First Name</dt>
<dd>Dominic</dd>
<dt>Age</dt>
<dd>24</dd>
<dt>E-mail</dt>
<dd>[email protected]</dd>
</dl>
However, obviously, the easiest way to display it in a table is using <table>
, <th>
and <td>
. You could hack together a table-layout using definition lists using something like this:
dt { float: left; clear: left; width: 6em; font-weight: bold; }
dd { float: left; }
<dl>
<dt>First Name</dt>
<dd>Dominic</dd>
<dt>Age</dt>
<dd>24</dd>
<dt>E-mail</dt>
<dd>[email protected]</dd>
</dl>
More info on the <dl>
tag available here.
Wow. We really have scared everyone off with the “Table layouts are evil! Use CSS!” stuff, haven't we?
A table — with <th>
for the labels and <td>
for the values — is perfectly applicable to this kind of content, gives you the rendering you want, and is at least as semantically correct as a definition list, arguably more so. Either are preferable to semantics-free divs.