Share!

How To Use DL, DT And DD HTML Tags To List Data vs Table List Data

Many past web designers would love to create web design using table and it has been the Achilles point for web developers when it comes to debugging. Now, however when it come to listing data on a web page, example listing data of a profile, many people would use a HTML table instead. In fact, by using HTML dl, dt, dd tags, you will save on writing more codes and add more semantic value to the content. Whereas table are best use for tabular data, and should not be use in listing data, web form or web layout.

If you are still creating list data using table, look below and compare on how to make your life easier with HTML dl, dt, dd tags.

DL, DT, DD Tags vs Table

It may both look identical, but look closely behind the codes.

Table List Data

A typical listing data using table can be as follow. First we have a tr table row to hold the title and the data td table cell. Then when we need to style the title element, we will need to give a class to that td table cell.

<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>

So over here in the CSS, we style the title class that we had declare in the HTML.

/*TABLE LIST DATA*/
table {
	margin-bottom:50px;
}

table tr .title {
	background:#5f9be3;
	color:#fff;
	font-weight:bold;
	padding:5px;
	width:100px;
}

table tr .text {
	padding-left:10px;
}

From here you can see that if you want to change the design or format for the title in the CSS, you will need to give each td for the title a class. If you want to style the data as well, you will need to give a class to it as well, so you are actually writing a lot of codes. More codes mean larger file size to download, more chances for bugs and harder for you to maintain.

DL, DT, DD List Data

Now, let's look at using HTML dl, dt, dd tags for listing the data. First we have the dl (definition list) tag to hold the whole set of data, next we have dt (defines the item in the list) tag and dd (describes the item in the list) tag to hold the title and the data.

<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>

Over at CSS, we will need to float the dt tag, so that the title for the list data will align to the left. The rest of the styling is up to you.

/*DL, DT, DD TAGS LIST DATA*/
dl {
	margin-bottom:50px;
}

dl dt {
	background:#5f9be3;
	color:#fff;
	float:left;
	font-weight:bold;
	margin-right:10px;
	padding:5px;
	width:100px;
}

dl dd {
	margin:2px 0;
	padding:5px 0;
}

From dl, dt, dd tags example, you can see that the codes are lesser, sleeker and much more semantic.

So if you are still using table to consolidate or list your data on the web form and web layout, it's really time now to make the switch. It's definitely going to make your life a lot more easier.

Advertise with us

Author

Terrance is a versatile web developer and one of the chief editor of OXP. He enjoys creating functional websites and is particularly engrossed in all the tiny details mixed together to construct great user experiences. He always believe that every web user deserves the best!

35 Comments

Say Something
  1. July 8, 2009 at 4:40 am

    Rather than using td.title I think it would be more appropriate to use a th element. It eliminates the need for the .title class (as well as the "text" class) and actually makes more sense.

    Name:
    John Don

    Wouldn't you agree?

    • Terrance
      July 8, 2009 at 9:06 am

      Hi Zack,

      Yes you are right.

      But even if you use "th" element, it is still not as semantic as using definition list.

      Thank for sharing. :)

      • Mitch
        June 22, 2011 at 3:03 am

        I don't think I understand what you mean when you call the use of 's as being more "semantic" than a table.

        I'm also confused as to what makes a table less sleek or more bulky. It seems to me that if you use instead of a title class then Zack is right. Could you specify what makes the method cleaner or better?

        • Mitch
          June 22, 2011 at 3:12 am

          My comment was formatted oddly. What it should have said was:

          I don't think I understand what you mean when you call the use of "DL"s as being more "semantic" than tables.

          I'm also confused as to what makes a table less sleek or more bulky. It seems to me that if you use "TH"s instead of a title class then Zack is right. Could you specify what makes the method cleaner or better?

  2. September 10, 2009 at 2:16 am

    Hi Terrance,
    Awesome tutorial and explanation. Thanks a lot. Keep doing the good work.

    With Regards,
    Sagar S. Ranpise

  3. Tom
    October 1, 2009 at 4:49 pm

    Hi,

    I have a small problem with the DL-way:

    when I tell the dl to have a "width: 50%", I get this result: http://img19.imageshack.us/img19/9537/ss20091001104849.png

    Can you help me with more css?

    • Terrance
      October 1, 2009 at 5:03 pm

      Hi Tom,

      Change width:50%; to pixel (px). If you want to keep it fluid with width:50%;, then add padding-left to your dl dd.

      hope this helps!

    • Zubair Ahmad
      November 9, 2009 at 4:49 pm

      Hello Tom,

      You can simple use this in css and may be sure that you will solve your problem

      dl {margin:0; padding:0;}
      dl dt{font-weight:bold; float:left;}
      dl dd{margin:0 0 2px 90px; padding:0;}

    • Zubair Ahmad
      November 9, 2009 at 4:55 pm

      If you want to change width then you can do and if you want to use same width in % or in pix, it is working with both.

  4. Cristian
    November 19, 2009 at 11:31 pm

    There are problems with dt, dd.

    In case the height of the content within dt is higher than of the content within dd, the dd is not resizing automatically to have the same height... This leads to lot of problems...

  5. December 20, 2009 at 5:29 pm

    Thanks for the information. That would really help clear a lot of doubts for a whole lot of people. It is always better to use more efficient code for better efficiency. Looking at it differently, this could also save the environment as better efficiency means more productivity using lesser resources. Now that is green coding. Our green news features many ways to use computers to save the environment.

  6. San
    December 28, 2009 at 8:19 pm

    How to make third column using this technique.

  7. Tom
    January 23, 2010 at 11:35 pm

    What can one do, if a is somewhat longer and goes over two lines? In your css the float breaks the whole layout. Is there a solutions using these tags?

  8. January 28, 2010 at 3:09 am

    The one that continues using tables is because it does not dominate or does not know CSS. To design in CSS is far better, by the subject of order, maintenance, accessibility, navigability and thousand reasons more.

  9. February 15, 2010 at 10:49 pm

    Use the th-Element for Head-Elements in the table and you will have the same. A table ist better to handle as the dt and dd, if you want to define absolute widths for it. I used at the Beginning the dt and dd-Elemnts by my Projekt and after many annoyed days i started to use tables. They are much better to handle and have saved me a lot of time.

    just my opinion.

    • Kevin
      June 5, 2010 at 9:35 am

      Using tables in 2010 for anything other than very complex tabular data (which is what tables were originally meant for anyway) is like keeping a leisure suit from the 70's on the basis that it still fits you. Just because you can, doesn't mean you should. Good luck - maybe we'll see you on page 499 of 500. :-)

  10. March 9, 2010 at 12:43 am

    Nice article, thought I'd just add my two cents to help the dd forms a little more obvious semantically.

    Field 1:

    I do still use table in my designs, although quite sparingly, they do have their uses still, particularly regarding backwards compatability.

    • March 9, 2010 at 12:44 am

      ahh, looks like the html is encoded into the post, d'oh!

  11. ppunsensor
    August 19, 2010 at 12:31 pm

    Greet Article, I'm looking for dl, dt, dd.

  12. Ming
    August 24, 2010 at 8:31 pm

    When I first saw people using it this way I was like Wow!
    Then I read http://www.w3.org/TR/html401/struct/lists.html#h-10.3

    Please correct me if I'm wrong. I think the purpose of DL, DT, DD is for definition (just my personal understanding from the documentation).

    I would generally use the below instead because these tags seem to be designed particularly for this purpose.
    - To display data - use label-span pair
    - To input data - use label-input pair
    And I apply the same style you use for DT to label.

    Thanks for sharing.

  13. Cliff Tyllick
    September 9, 2010 at 8:09 pm

    @Ming, one thing upsets me about your comment: That it took 15 months before someone reading this page pointed it out! You are absolutely right — this is an inappropriate use of DL, DT, and DD.

    DL should mark a list of definitions — a glossary, for example.

    DT marks a term to be defined, not a label for a field.

    DD marks the definition of that term, not a data field.

    As you point out, CSS is the tool to use to control the appearance of text. The html tags are to be used to label the semantic structure of each item. The take-home lesson is to learn the purpose of each tool in the kit provided through the W3C and then to use a tool for its intended purpose.

    Lighter code is still junk code if it's semantically incorrect.

    • vin
      April 13, 2011 at 9:32 pm

      +1

  14. Adedoyin Kassem
    September 30, 2010 at 10:13 pm

    Nice tutorial you have posted here but your CSS rules for the and tags have not put one thing into consideration.
    Assume that your s all have one line as your example here has clealy show but one or two tags contain contents that span across two lines, what would happen then? There would be a distortion of the total structure.

    Now don't get me twisted, i don't use tables for my layouts (only when necessary) but your execution of this stylesheet isn't carefully thought about.

  15. Neil
    November 18, 2010 at 9:21 am

    Be sure to add "clear:both;" in the css to make sure each row always lines up regardless of the height.

    dl dt {
    float:left;
    clear:both;
    width:100px;
    }
    dl dd {
    float:left;
    }

  16. January 6, 2011 at 11:02 pm

    Wow, that was incredibly helpful. I have been making websites and this will look much nicer and be way easier to implement. Thank you for the really helpful guide, your blog is really awesome!

  17. Luiz
    January 28, 2011 at 11:25 pm

    I'm with Cliff Tyllick, this isn't a correct use of DL,DT and DD.

    They should contain terms and their definitions. "Luiz" isn't the definition of "Name", for example.

    I believe the table approach would be more semantically correct.

  18. Lenny
    May 25, 2011 at 3:05 am

    Will using dl and dt effect google seo?

    • Cliff Tyllick
      June 12, 2011 at 5:47 am

      @Lenny, I can't imagine how using dl/dd/dt as opposed to a tabular layout would have any effect whatsoever on SEO.

      The most important factors for SEO that are under the author's control are the words in these places:

      The Web page's URL
      Links pointing to it from elsewhere on the same website
      Its title tag
      Its properly tagged headings
      To a much lesser degree, its contents

      Two other very important factors that are usually not under the author's control are the words in links pointing to the Web page from other websites and the perceived authority of those other websites.

      But the markup of data tables and lists? You want to do it right for a lot of reasons, but SEO isn't one of them.

  19. June 7, 2011 at 6:40 pm

    Nice....
    I Want try. Thx 4 share....

  20. onebyelove
    June 8, 2011 at 7:26 pm

    trhrthrt

  21. charly
    June 26, 2011 at 11:00 am

    Being still new at WEB Dev, I'm just finding out about DL/DT/DD. And reading about the benefits of good semantics (so encouraged by HTML5 by the way), I'm starting to understand more things, it's like the second level of understanding after initially using CSS. This would really make it good for two-column presentation (using it a lot in a business app now with lots of CRUD single-record screens) as I could style this kind of view separately from other table views (like multi column table queries). Thanks!!

  22. October 5, 2011 at 10:16 pm

    i make html designs for 5 years and dl is 100% better than table.

  23. gabriel
    October 26, 2011 at 3:07 am

    to anyone claiming this is better than table... care to explain how you make variable lengths of text all aligned?

    with TDs the rows will be aligned just fine. with DTs you have to fix one width and live with it for the entire site.

    • January 31, 2012 at 9:50 am

      yes, depending on how many columns you have you use a %. for eg if you have 2 columns you put

      dl dt
      {
      width: 50%;
      }

  24. jatinpatel
    February 1, 2012 at 5:07 pm

    very good

Please note that comments are moderated - and rel="nofollow" is in use. Please no link dropping, no keywords or domains as names. Kindly do not spam, and do not advertise!