Can I put anything inside DL/DT/DDs?
Asked Answered
H

3

24

can I use definition lists just like unordered/ordered lists?

I mean insert DIVs any anything I want inside DT or DD?

<dl>
  <dt>
    ...
  </dt>
  <dd>
    ...
  </dd>
</dl>

Do any browsers, or search engines complain?

Haver answered 17/6, 2011 at 22:36 Comment(1)
Do search engines complain? I think they only complain when we whip them but don't feed them.Sontag
H
24

Updated answer based on comments:

This was originally answered in 2011 for HTML 4, but the answer is different for HTML5:

dt Flow content, but with no header, footer, sectioning content, or heading content descendants. dd Flow content.

Original answer:

DT elements should contain inline content.
DD elements should contain block-level content.

Definition lists vary only slightly from other types of lists in that list items consist of two parts: a term and a description. The term is given by the DT element and is restricted to inline content. The description is given with a DD element that contains block-level content.

Source: W3C

This question is also an interesting read: Why use definition lists (DL,DD,DT) tags for HTML forms instead of tables?

Holland answered 17/6, 2011 at 22:46 Comment(5)
How come you don't use the W3C documentation? It is doctype-related. For instance, HTML 4.01: w3.org/TR/html401/struct/lists.html#h-10.3Sontag
@Jared Farrish: You're right and the original info was wrong! Updated.Holland
No problem; always best to go to the source. :)Sontag
@Jared Farrish: I know - more often than not it's sites like About and W3Schools that rank higher in search results despite containing inaccurate information. Damn you Google! ;) All updated with reputable sources now.Holland
The answer is not valid anymore as you can have flow content in both <dt> and <dd> elements according to w3.org/TR/html5/grouping-content.html#the-dt-elementJaynejaynell
G
12

Inside a DL you can only put DT and DD tags. A DT tag is an inline tag, so you should not put block elements in it. A DD tag can contain basically anything you want, it's a flow content tag.

Gonzalogoo answered 17/6, 2011 at 22:50 Comment(0)
H
6

As of December 2017 according to HTML 5.2 Specification, you can now add a single nested <div> tag inside a <dl> tag, I assume for styling purposes:

https://www.w3.org/TR/html52/grouping-content.html#the-dl-element

Content model:

Either: Zero or more groups each consisting of one or more dt elements followed by one or more dd elements, optionally intermixed with script-supporting elements.

Or: One or more div elements, optionally intermixed with script-supporting elements.

Holloway answered 2/3, 2020 at 16:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.