Curriculum
HTML description lists, represented by the <dl>
(description list), <dt>
(term), and <dd>
(description) elements, are used to organize and display definitions, explanations, or other term-to-description relationships. Description lists are ideal for presenting glossaries, FAQs, and other content that pairs terms with corresponding explanations. In this lesson, we’ll explore HTML description lists, how to create them, customize their appearance, and use them effectively.
Prerequisites: Basic knowledge of HTML and text editing.
HTML description lists are used to create pairs of terms and their corresponding explanations or descriptions. A description list consists of the following elements:
<dl>
: The container for the description list.<dt>
: The term, representing the word or concept to be defined.<dd>
: The description, providing the explanation or definition of the term.A description list includes <dt>
and <dd>
elements within the <dl>
element. Each <dt>
is followed by one or more <dd>
elements.
<dl> <dt>Term 1</dt> <dd>Description 1</dd> <dt>Term 2</dt> <dd>Description 2</dd> </dl>
To create a basic description list, use the <dl>
element to enclose term (<dt>
) and description (<dd>
) pairs.
<dl> <dt>HTML</dt> <dd>Hypertext Markup Language</dd> <dt>CSS</dt> <dd>Cascading Style Sheets</dd> </dl>
You can nest description lists within other description lists to create hierarchical relationships.
<dl> <dt>Web Technologies</dt> <dd> <dl> <dt>HTML</dt> <dd>Hypertext Markup Language</dd> <dt>CSS</dt> <dd>Cascading Style Sheets</dd> </dl> </dd> <dt>Programming Languages</dt> <dd> <dl> <dt>JavaScript</dt> <dd>A scripting language</dd> <dt>Python</dt> <dd>An interpreted language</dd> </dl> </dd> </dl>
Use CSS to style description lists, allowing you to change fonts, margins, and other visual aspects.
/* Example CSS for description list styling */ dl { margin-left: 20px; /* Adjust left margin for the entire list */ } dt { font-weight: bold; /* Make terms bold */ } dd { margin-left: 10px; /* Indent descriptions */ }
Use description lists for presenting term-to-description relationships, such as glossaries, definitions, or FAQs.
Ensure your description lists are accessible by providing meaningful text for terms and descriptions and adhering to semantic HTML.