Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct way to combine a definition list with an ordered list?

Tags:

html

I want to make an ordered definition list. Should I nest an <ol> in a <dl>, or the other way around?

i.e.

<h4>Bike Descriptions</h4>
<dl>
    <ol>
        <li>
            <dt>Giant Bikes</dt>
            <dd>Bikes that are very sturdy and reliable.</dd>
        </li>
        <li>
            <dt>Walmart Bikes</dt>
            <dd>Bikes that are crummy and heavy.</dd>
        </li>
    </ol>
</dl>

Or nest the <dl> within <ol> or even within each <li>?

The docs don't seem to say.

like image 357
LazerSharks Avatar asked Jul 30 '16 05:07

LazerSharks


People also ask

What is the correct tag for an ordered list?

The <ol> tag defines an ordered list. An ordered list can be numerical or alphabetical. The <li> tag is used to define each list item.

What is order unordered and definition lists in HTML?

Lesson Summary As we learned, HTML provides you with three types of lists: Ordered lists, which have an inherent order and each item is numbered. Unordered lists, which have no inherent order and each item is bulleted. Description lists, which contain a list of terms and descriptions for each term.


2 Answers

According to that documentation, the only elements a <dl> may contain are <dt> and <dd>:

Content model:

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.

Thus, your example code is invalid HTML. The only valid way to nest dl and ol/ul is in the order ol/ul > li > dl > dt+dd:

<h4>Bike Descriptions</h4>    
<ol>
    <li>
        <dl>
            <dt>Giant Bikes</dt>
            <dd>Bikes that are very sturdy and reliable.</dd>
        </dl>
    </li>
    <li>
        <dl>
            <dt>Walmart Bikes</dt>
            <dd>Bikes that are crummy and heavy.</dd>
        </dl>
    </li>
</ol>
like image 198
Rory O'Kane Avatar answered Nov 15 '22 10:11

Rory O'Kane


Your example is not a valid HTML tag. Perhaps you would like to do something like this.

<h4>Bike Descriptions</h4>    
<ul>
  <li>
    <dl>
      <dt>Giant Bikes</dt>
      <dd>Bikes that are very sturdy and reliable.</dd>
    </dl>
  </li>
  <li>
    <dl>
      <dt>Walmart Bikes</dt>
      <dd>Bikes that are crummy and heavy.</dd>
    </dl>
  </li>
</ul>

Then you can add style to your CSS to fix the layout.

like image 27
iMarkDesigns Avatar answered Nov 15 '22 10:11

iMarkDesigns