HTML <dd> Tag
The HTML <dd>
tag is used to define the description or definition of a term in a description list. It is a child element of the <dl>
(description list) element and is paired with the <dt>
tag, which defines the term being described.
The combination of <dl>
, <dt>
, and <dd>
tags is used to create semantic and structured lists for definitions, key-value pairs, or other descriptive content.
Basic Syntax of HTML <dd> Tag
The basic structure of a description list using the <dd>
tag is:
<dl>
<dt>Term 1</dt>
<dd>Description of Term 1</dd>
<dt>Term 2</dt>
<dd>Description of Term 2</dd>
</dl>
The <dd>
tag must always appear inside a <dl>
element and immediately follow a <dt>
tag.
Attributes of HTML <dd> Tag
- Global Attributes: The
<dd>
tag supports all global attributes, such asclass
,id
,style
, anddata-*
. - Event Attributes: The
<dd>
tag supports all event attributes, such asonclick
,onmouseover
, andonkeydown
.
Basic Example of HTML <dd> Tag
Here’s a simple example of a description list using the <dd>
tag:
index.html
<!DOCTYPE html>
<html>
<body>
<h2>Description List Example</h2>
<dl>
<dt>HTML</dt>
<dd>A markup language used to create web pages.</dd>
<dt>CSS</dt>
<dd>A stylesheet language used to style web pages.</dd>
<dt>JavaScript</dt>
<dd>A programming language used to create interactive web pages.</dd>
</dl>
</body>
</html>
Explanation: The <dt>
tags define the terms, while the <dd>
tags provide their corresponding descriptions. This creates a semantic list of definitions.
Using the <dd> Tag for Key-Value Pairs
The <dd>
tag can also be used for key-value pair representations, such as technical specifications:
index.html
<!DOCTYPE html>
<html>
<body>
<h2>Product Specifications</h2>
<dl>
<dt>Processor</dt>
<dd>Intel Core i7</dd>
<dt>RAM</dt>
<dd>16 GB</dd>
<dt>Storage</dt>
<dd>512 GB SSD</dd>
</dl>
</body>
</html>
Explanation: Each <dt>
tag represents a product feature, while the corresponding <dd>
tag describes its value.
Styling the <dd> Tag with CSS
The <dd>
tag can be styled using CSS for better visual presentation:
index.html
<!DOCTYPE html>
<html>
<head>
<style>
dt {
font-weight: bold;
color: #333;
color: green;
}
dd {
margin-left: 20px;
color: #555;
font-style: italic;
}
</style>
</head>
<body>
<h2>Styled Description List</h2>
<dl>
<dt>Sun</dt>
<dd>The star at the center of our solar system.</dd>
<dt>Earth</dt>
<dd>The third planet from the Sun.</dd>
<dt>Moon</dt>
<dd>The natural satellite of Earth.</dd>
</dl>
</body>
</html>
Result: The <dt>
tags appear bold and green, and the <dd>
tags are indented and styled italic with a lighter color for differentiation.
Special Cases for HTML <dd> Tag
Using Multiple Descriptions for a Single Term
A single term (<dt>
) can have multiple descriptions (<dd>
):
index.html
<!DOCTYPE html>
<html>
<body>
<h2>Multiple Descriptions Example</h2>
<dl>
<dt>JavaScript</dt>
<dd>A programming language for the web.</dd>
<dd>Used for building dynamic and interactive web applications.</dd>
</dl>
</body>
</html>
Explanation: The term JavaScript
has two associated descriptions, each within a separate <dd>
tag.