HTML <dl> Element

Publish in HTML Tutorial el 23/05/2025 19:57

The <dl> Element: Definition Lists in HTML

The <dl> element represents a description list in HTML. It's used to create a list of terms and their corresponding descriptions, making it perfect for glossaries, metadata displays, or any name-value pair listings. The <dl> element works in conjunction with <dt> (definition term) and <dd> (definition description) elements.


Basic Structure

Here's how a basic definition list is structured:

When rendered, it looks like:

Term 1
Description for term 1
Term 2
Description for term 2


Tips and Tricks

  • You can have multiple <dd> elements for a single <dt>
  • Use CSS to style definition lists as accordions or FAQs
  • Screen readers understand the relationship between <dt> and <dd>
  • Great for displaying metadata like "Author: John Doe"
  • You can nest other HTML elements inside <dd> elements


Examples of <dl> Usage

1. Basic Glossary Example

A simple glossary of web development terms:

Play Code


2. Multiple Descriptions for One Term

Showing different meanings for the same term:

Play Code


3. FAQ Section

Creating a simple FAQ section using definition lists:

Play Code


4. Dynamic DL with JavaScript

Adding items to a definition list using JavaScript:

Play Code


5. Interactive Filterable DL

Filtering a definition list based on user input:

Play Code


Conclusion

The <dl> element is a semantic HTML element that provides a perfect structure for name-value pairs. While often overlooked, it's incredibly useful for creating accessible, well-structured content like glossaries, FAQs, and metadata displays. The examples above demonstrate both basic and advanced uses, including JavaScript integration for dynamic content.

También te puede interesar

HTML <style> Element
HTML <style> Element

The <style> HTML element contains style information for a document, or part of a document. ...

HTML <strong> Element
HTML <strong> Element

The <strong> element is used to indicate that its content has strong importance, seriousnes...

HTML <span> Element
HTML <span> Element

The <span> element is an inline container used to mark up a part of a text or document. Unl...

HTML <source> Element
HTML <source> Element

The <source> element is used to specify multiple media resources for media elements like &l...

HTML <small> Element
HTML <small> Element

The <small> element is used to represent side-comments and small print, typically for discl...

HTML <section> Element
HTML <section> Element

HTML <section> Element: The Complete Guide The <section> element is a semantic HTML ...