Search code examples
htmlsemantics

Adding a title to more than one definition list?


I wish to have multiple definition lists and have a single title for these lists, for example:

 //how can I add the title of "Items in fridge"
 <dl>
   <dt>Food:</dt>
   <dd>Eggs</dd>
   <dd>Bacon</dd>
 </dl>
 <dl>
   <dt>Drinks:</dt>
   <dd>Water</dd>
   <dd>Juice</dd>
 </dl>

What's the correct way to add an overall <dt> to various definition lists


Solution

  • Not 100% sure I understand the question correctly, but maybe put them in a <section>?

    <section>
      <h1>Items in Fridge</h1>
      <dl>
        <dt>Food:</dt>
        <dd>Eggs</dd>
        <dd>Bacon</dd>
      </dl>
      <dl>
        <dt>Drinks:</dt>
        <dd>Water</dd>
        <dd>Juice</dd>
      </dl>
    </section>
    

    (note: there was another solution in my post originally but, as Alohci pointed out in the comments, it wasn't valid HTML)