Sometimes your content is a set of name and value pairs: a glossary term and its definition, a product feature and its detail, a question and its answer. HTML has a dedicated structure for that, the description list.
The three elements#
<dl>(description list) wraps the whole list.<dt>(description term) holds a name, term or label.<dd>(description details) holds the matching description or value.
<h2>Coffee glossary</h2>
<dl>
<dt>Espresso</dt>
<dd>A small, concentrated coffee made by forcing hot water through fine grounds.</dd>
<dt>Crema</dt>
<dd>The golden foam that floats on top of a fresh espresso.</dd>
<dt>Roast</dt>
<dd>The heating process that turns green beans brown and develops flavour.</dd>
</dl>By default, browsers indent each <dd> under its term. CSS can change that into a two-column layout.
Multiple terms and multiple descriptions#
One term can have several descriptions, and several terms can share one description:
<dl>
<dt>Cappuccino</dt>
<dd>Equal parts espresso, steamed milk and foam.</dd>
<dd>Often dusted with cocoa powder.</dd>
<dt>Decaf</dt>
<dt>Decaffeinated</dt>
<dd>Coffee with at least 97 percent of the caffeine removed.</dd>
</dl>Key facts for a page#
Description lists are excellent for "at a glance" details, such as a cafe's contact information:
<dl>
<dt>Address</dt>
<dd>12 Lakeside Road, Pokhara</dd>
<dt>Opening hours</dt>
<dd>Every day, 7am to 7pm</dd>
<dt>Wi-Fi</dt>
<dd>Free for customers</dd>
</dl>Grouping pairs with div#
HTML allows you to wrap each term and its descriptions in a <div> inside the <dl>. This is handy for styling each pair as a card and does not change the meaning:
<dl>
<div>
<dt>Question</dt>
<dd>Do you have vegan options?</dd>
</div>
<div>
<dt>Answer</dt>
<dd>Yes, oat and soy milk, and a vegan brownie.</dd>
</div>
</dl>When to use something else#
- A plain list of items with no labels: use
ulorol. - Data with several columns of values: use a table.
- A FAQ with expand-and-collapse behaviour: consider
<details>and<summary>, which you will meet near the end of this tutorial.
Common mistakes#
- Using
<dt>and<dd>outside of a<dl>. - Using a list of paragraphs with bold text where a description list fits better.
- Putting headings inside
<dt>just for size. Keep terms short and textual. - Forgetting that a
ddwithout a precedingdtis invalid.
Try it yourself#
Build a mini glossary with four web terms (for example HTML, browser, URL, attribute) using dl, dt and dd. Give one term two descriptions. Then create an "At a glance" list for a project of yours with address, hours and phone as pairs, and wrap each pair in a div.
Recap#
A description list (dl) pairs terms (dt) with descriptions (dd). It suits glossaries, key facts and simple question-and-answer content. You may group each pair in a div for styling.
Check your understanding
Lesson quiz
OptionalA short quiz to check what you just learned.
- Questions
- 3
- Time limit
- 5 min
- Pass mark
- 70%
- Best score
- -