HTML・Organizing information

A list of terms and descriptions

For when "a word" and "its description" line up as a set. With dl, dt, and dd, glossaries and Q&As come out neatly organized.

Glossaries, frequently asked questions, profile items—there are quite a lot of situations where “a name” and “its content” line up as a pair, right? What fits perfectly in those cases is the definition list. It’s a dedicated kind of list, separate from the <ul> list.

Let’s write one

Let’s line up two “term → description” pairs.

<dl>
  <dt>HTML</dt>
  <dd>The language that builds the framework of a web page.</dd>

  <dt>CSS</dt>
  <dd>The language that arranges the look of a page.</dd>
</dl>

Broken down, it looks like this.

TagMeaning
<dl>definition list, the “container” for the whole definition list
<dt>definition term, the word being described (the heading side)
<dd>definition description, its description (the content side)

In many browsers, <dd> (the description) is shown slightly indented to the right, so even the look conveys “ah, this is the description of that word.” Here’s the actual display.

Below <dt> (the word), <dd> (the description) hangs one step down—the pair relationship shows even in the look.

Several descriptions for one word

You can also attach several <dd> to a single <dt>.

<dl>
  <dt>Long-tailed tit</dt>
  <dd>A small bird that lives in Hokkaido.</dd>
  <dd>Its pure-white, round appearance earns it the nickname "snow fairy."</dd>
</dl>

It’s handy when you want to add a few lines of description to a single word.

You can see two <dd> hanging from a single <dt>.

Describing similar words together

Conversely, you can line up several <dt> and bring them together under one <dd>. It’s handy for a word that goes by several names.

<dl>
  <dt>PC</dt>
  <dt>Personal computer</dt>
  <dd>A computer used by an individual.</dd>
</dl>

The same description hangs under both “PC” and “Personal computer.” Using it in a glossary when “there are several names with the same meaning” saves you from writing the description twice.

Even with two <dt> lined up, there’s just one <dd> below. The same description hangs from both words.

It works for Q&A too

“A pair of a word and a description” is also a perfect match for a pair of a question and an answer. Make the question <dt> and the answer <dd>, and it becomes a mini-FAQ just like that.

<dl>
  <dt>How are HTML and CSS different?</dt>
  <dd>HTML is the framework of a page, and CSS is the language that arranges its look.</dd>

  <dt>How many tags do I need to memorize?</dt>
  <dd>You don't have to cram them all at once. They gradually add up as you use them.</dd>
</dl>

Not just glossaries—<dl> also comes in handy when you’re building a frequently-asked-questions section.

Just by using <dl>, the question-and-answer pairs take on the look of a mini-FAQ.

Summary of this lesson

  1. In a definition list, <dt> (word) and <dd> (description) line up inside <dl>
  2. It’s fine to attach several <dd> to a single <dt>
  3. Choose it when you have “a pair of a word and a description”

Try it

The “definition list” we learned this time (<dl> / <dt> / <dd>) is not used on Shima’s page. It’s a tool for pages where “a word and its description” line up in pairs, like glossaries, Q&As, and spec tables. Keep it in mind, and use it when you need it.

FAQ

Is it okay if the numbers of dt and dd don't match?
Yes. One dt can have several dd, and the other way around, two dt can share one dd. Unlike a table, there's no rule that the numbers have to match.
Can I use dl for a FAQ page?
It's well suited to it. Making the questions dt and the answers dd fits the definition-list shape of 'a word and its description' perfectly.
Can I put longer content or a list inside dd?
Yes. It's fine to put a p, several lines of text, a ul bulleted list, and so on inside dd. It also works for a glossary where the descriptions get long.