views:

40

answers:

5

Hi,

Does definition list <dl> require that each <dd> will have <dt> tag?

Example:

option1 for each <dd> exist his <dt> also if <dt> empty:

<dl>
<dt></dt>
<dd>value1</dd>
<dt>name2</dt>
<dd>value2</dd>
</dl>

option2 for each <dd> not exist his <dt> if <dt> empty:

<dl>

<dd>value1</dd>
<dt>name2</dt>
<dd>value2</dd>
</dl>


Edit:

Example for when dt can be empty (its build by zend_form auto - can not be changed):

<dl> 

<dt><lable>Last Name:</label></dt> 
<dd><input type='text' size='30' /></dd>
<dt><lable></label></dt> 
<dd><input type='submit' size='30' value='submit'/></dd>
<dt><lable>Name:</label></dt> 
<dd><input type='text' size='30' /></dd>

</dl>

Thanks

+2  A: 

HTML 4 doesn't enforce this, neither is XHTML 1.1. They only require <dl> contains only one or more <dt> or <dd>s.

However, HTML 5 has stricter requirement:

zero or more of: (one or more <dt> elements, followed by one or more <dd> elements)

Hence, your option2 will not validate in HTML 5.

option1 is still fine, as <dt> can contain any "phrasing content", including empty content.

KennyTM
+1  A: 

The tag is used in conjunction with (defines the definition list) and (describes the item in the list).
Copied from W3.

Tom
+2  A: 

A dl containing only dds validates in the W3C validator, so I guess it's okay.

W3C HTML 4.01 Reference: 10.1 Introduction to lists

Working example:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
  <dl>
   <dd>value1</dd>
   <dd>value2</dd>
 </dl>
</body>
</html>
Pekka
+1  A: 

It is valid, but I can't see why you'd ever want to do it.

Note that your second example only really applies to the first item; there is no such thing as a missing dt later on, as multiple dd items can apply for a single dt.

Example for my case that explain better:<dl><dt><lable>Name:</label></dt><dd><input type='text' size='30' /><dt><lable></label></dt><dd><input type='submit' size='30' value='submit'/></dl>
Yosef
+3  A: 

According to the HTML 4 DTD:

<!ELEMENT DL - - (DT|DD)+              -- definition list -->

That means you can mix and match.

Here is a nice overview of the various ways to use a definition list:

Tomalak
+1, this is the most definitive resource. Is there a good introduction to interpreting DTD syntax somewhere?
Pekka
@Pekka: Straight-forward and sufficient - http://en.wikipedia.org/wiki/Document_Type_Definition#Element_type_declarations ;-)
Tomalak
@Tomalak cheers. :)
Pekka