EthicsComputerCourses
Join training +91 90532 10052

Description Lists

HTML · Lesson 17 of 234 Beginner 8 min read Updated

By the end of this lesson you will build glossaries, product specification boxes and FAQ sections with description lists, group them correctly, and lay them out neatly with a few lines of CSS grid.

You saw a short description list in Ordered & Unordered Lists. Here we go deeper: the exact rules, the patterns real sites use, and the mistakes that make a validator complain.

What a description list really is

A description list, <dl>, holds name-value groups. Each group has one or more names in <dt> (description term) and one or more values in <dd> (description details).

Think of the details printed on your railway ticket: "PNR: 4521...", "Train: 12015", "Coach: C3". Each line is a label with a value. That is a name-value group, and a <dl> is the HTML for it.

The HTML standard says the groups can be terms and definitions, metadata topics and values, or questions and answers. So <dl> is wider than a dictionary. The rules for what goes inside are strict, though:

ElementMay containNotes
<dl>Groups of <dt> then <dd>, or <div> wrappersNot <li>, <p> or text directly
<dt>Text and inline content, even paragraphsNo headings, <header>, <footer> or sections inside
<dd>Any flow content: paragraphs, lists, images, linksIndented by default in browsers
<div> inside <dl>One or more <dt> followed by one or more <dd>All groups must use a <div>, or none of them

Each name should appear only once in a list. If two groups have the same <dt> text, merge them into one group with two <dd> elements.

Step 1: a glossary

A glossary is the classic use. Inside each <dt>, wrap the word in <dfn>, the defining instance element, to say "this is where the term is defined".

HTMLOpen in editor
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Cricket glossary</title>
</head>
<body>
  <h1>Cricket words for new fans</h1>
  <dl>
    <dt><dfn>Duck</dfn></dt>
    <dd>When a batter is out without scoring a single run.</dd>

    <dt><dfn>Maiden over</dfn></dt>
    <dd>An over of six balls in which the batting side scores no runs.</dd>

    <dt><dfn>Yorker</dfn></dt>
    <dd>A ball that lands right at the batter's feet, which is hard to hit.</dd>
  </dl>
</body>
</html>

You should see each term on its own line with the description indented below it. The indent comes from the browser's default style for <dd>, which adds a margin on the starting side. Notice that <dt> is not bold by default; you style that with CSS.

Step 2: several terms or several descriptions

A group is not limited to one <dt> and one <dd>. Two common shapes:

HTML
<dl>
  <!-- Two terms that share one description -->
  <dt>Vada pav</dt>
  <dt>Bombay burger</dt>
  <dd>A spicy potato fritter in a soft bun, a famous Mumbai street snack.</dd>

  <!-- One term with two descriptions -->
  <dt>Pitch</dt>
  <dd>The strip of ground in the middle of a cricket field.</dd>
  <dd>A short talk to sell an idea, as in a startup pitch.</dd>
</dl>

The first group gives two names for the same thing. The second gives two meanings of one word. The browser knows which <dd> elements belong to which <dt> from their order: every run of <dt> elements followed by a run of <dd> elements forms one group.

Step 3: product specs with div wrappers and CSS grid

Online shops show a "Specifications" box: brand, battery, weight, warranty. This is metadata, which means data about the product, and it fits a <dl> perfectly.

The HTML standard lets you wrap each group in a <div>. The wrapper adds no meaning, but it gives you a box per row that you can style, for example with a border line under each row. Remember the rule: wrap all groups or none.

HTMLOpen in editor
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Product specifications</title>
  <style>
    .specs { max-width: 28rem; margin: 0; }
    .specs div {
      display: grid;
      grid-template-columns: 9rem 1fr;
      gap: 1rem;
      padding: 0.5rem 0;
      border-bottom: 1px solid #ddd;
    }
    .specs dt { font-weight: bold; }
    .specs dd { margin: 0; grid-column: 2; }
  </style>
</head>
<body>
  <h1>Kabir Power Bank 20000</h1>
  <p>Price: ₹1,299</p>
  <h2>Specifications</h2>
  <dl class="specs">
    <div>
      <dt>Capacity</dt>
      <dd>20,000 mAh</dd>
    </div>
    <div>
      <dt>Ports</dt>
      <dd>2 USB-A</dd>
      <dd>1 USB-C</dd>
    </div>
    <div>
      <dt>Weight</dt>
      <dd>410 g</dd>
    </div>
    <div>
      <dt>Warranty</dt>
      <dd>1 year, service centres in Pune and Jaipur</dd>
    </div>
  </dl>
</body>
</html>

You should see a neat two-column table-like box. Each <div> is a small grid with a fixed label column and a flexible value column. The rule grid-column: 2 keeps every <dd> in the value column, so the second <dd> for "Ports" drops onto a new row on the right instead of under the label. If you remove margin: 0, the values move right because of the default indent.

You could also put display: grid on the <dl> itself, with grid-template-columns: max-content 1fr. That works well when every group has exactly one <dt> and one <dd>. You will learn grid properly in CSS Grid Introduction.

Pattern: a simple FAQ

A list of questions and answers is also a set of name-value groups, so <dl> is a valid choice:

HTML
<dl class="faq">
  <dt>Do you deliver outside Kochi?</dt>
  <dd>Yes, we deliver anywhere in Kerala within three days.</dd>

  <dt>Can I pay by UPI?</dt>
  <dd>Yes. We accept UPI, cards and cash on delivery.</dd>
</dl>

Know the limits. A <dt> cannot contain a heading, so the questions will not appear in a screen reader's list of headings. For a long FAQ, many sites prefer a heading for each question, or the collapsible <details> element from Details & Summary Elements. For five or six short questions on one page, a <dl> is clean and correct.

When not to use a description list

  • Dialogue. The standard says <dl> is not suitable for a conversation between people. Use paragraphs, perhaps with the speaker's name in <b> or <strong>.
  • Data with more than two columns. A train timetable with station, arrival and departure needs a <table>. See HTML Tables Fundamentals.
  • Just for the indent. If you only want text pushed to the right, use CSS margin or padding.

Common mistakes

  • Putting <li> or <p> directly inside <dl>. Only <dt>, <dd>, <div> wrappers and script-supporting elements may be direct children.
  • Wrapping only some groups in <div>. It is all or none.
  • A <dd> before any <dt>. Every group starts with a name.
  • Headings inside <dt>. Not allowed; put the heading before the list or use a different pattern.
  • Repeating the same term in two groups. Merge them into one group with several <dd> elements.

Interview questions

1. What are <dl>, <dt> and <dd> used for?

They mark up name-value groups. <dl> is the list, <dt> holds a name such as a term, label or question, and <dd> holds its value, description or answer. Glossaries, product specifications and metadata blocks are typical uses.

2. Can one term have several descriptions?

Yes. A group is one or more <dt> elements followed by one or more <dd> elements. So one term can have two meanings, and two synonyms can share one description.

3. Is it valid to put a <div> inside a <dl>?

Yes, the HTML Living Standard allows a <div> around each name-value group, mainly for styling. Each <div> must contain <dt> elements followed by <dd> elements, and if you wrap one group you must wrap them all.

4. When would you choose a table instead of a description list?

When the data has more than two dimensions or needs column headers, such as a timetable or a marks sheet with several subjects. A <dl> suits simple label and value pairs.

5. Why might you not use <dl> for a long FAQ?

A <dt> cannot contain headings, so questions in a <dl> do not appear in screen reader heading navigation. A long FAQ is easier to scan with a heading per question or with <details> elements.

Key points

  • <dl> holds name-value groups: one or more <dt> followed by one or more <dd>.
  • Use it for glossaries, metadata such as product specs, and short question and answer lists.
  • Wrap the term in <dfn> inside <dt> when the list defines words.
  • A <div> may wrap each group for styling, but then every group needs one.
  • <dt> cannot contain headings; <dd> can contain any flow content.
  • CSS grid turns a <dl> into a tidy two-column layout; remove the default <dd> margin.

Exercise

Create a "Student profile" card for Isha, a Class 12 student in Jaipur. Use a description list with div wrappers for: name, roll number, stream, subjects (three <dd> elements under one <dt>), and hobbies. Style it with CSS grid so labels sit in a left column 8rem wide and values on the right, with a thin line under each row.

Show solution
HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Student profile</title>
  <style>
    .profile div { display: grid; grid-template-columns: 8rem 1fr; gap: 1rem; padding: 0.4rem 0; border-bottom: 1px solid #ccc; }
    .profile dt { font-weight: bold; }
    .profile dd { margin: 0; grid-column: 2; }
  </style>
</head>
<body>
  <h1>Student profile</h1>
  <dl class="profile">
    <div><dt>Name</dt><dd>Isha Choudhary</dd></div>
    <div><dt>Roll number</dt><dd>12B-17</dd></div>
    <div><dt>Stream</dt><dd>Science</dd></div>
    <div>
      <dt>Subjects</dt>
      <dd>Physics</dd>
      <dd>Chemistry</dd>
      <dd>Mathematics</dd>
    </div>
    <div><dt>Hobbies</dt><dd>Chess and classical dance</dd></div>
  </dl>
</body>
</html>

Every group has its own <div>, so the rule "all or none" is met. The three subjects are three <dd> elements in one group, and the grid places them under each other in the value column.

Quick Quiz

1. Which of these is a valid direct child of <dl>?

2. Two words mean the same thing and share one description. How do you mark it up?

3. What is the rule for <div> wrappers in a <dl>?

4. Why are <dd> elements indented on a plain page?

Learn HTML with a mentor

Free lessons get you started. Our Full Stack Web Development training adds real projects and code reviews from working developers.

  • Project-based learning
  • Mentor code reviews
  • Free counselling call