日本語

How to Fix the Lighthouse “dl’s do not contain only properly-ordered dt and dd groups” Error

​​Lighthouse​Accessibility,HTML

When you write a list of "name and value" pairs, such as a profile, an FAQ, or product specifications, with a <dl> and put a heading or a decorative <span> inside it, Lighthouse's Accessibility audit reports "<dl>'s do not contain only properly-ordered <dt> and <dd> groups." If the direct children of the <dl> are only <dt> and <dd> pairs, or <div> elements that each wrap one pair, the warning goes away. In the Japanese report, the message reads: "<dl> contains elements other than properly ordered <dt> and <dd> groups, <script>, <template>, or <div> elements."

On the page I tested, the Accessibility score was 79. After the fix, it was 100.

Note

The test environment was Ubuntu 24.04, Node.js 22, and Lighthouse 13.6.0 (the npm package; the axe-core it uses is 4.14.0). I pointed the CHROME_PATH environment variable at Chrome for Testing 158, which is bundled with Playwright 1.63.0. I ran Lighthouse from the command line with the default mobile settings and checked only the accessibility category. The test pages were served from a server I ran in the test environment at localhost:8080. I did not test the Lighthouse panel in Chrome DevTools, PageSpeed Insights, or actual screen reader output.

A profile dl with an h2 and a span

The warning appeared on the page below. The <dl> for a cat's profile contains an <h2> heading, and the second pair is wrapped in a <span> for styling. The FAQ below it is not in a <dl>. Its <dt> and <dd> are placed inside a <div>.

html
<dl class="profile">
  <h2>みけのプロフィール</h2>
  <dt>年齢</dt>
  <dd>3さい</dd>
  <span class="row"><dt>好物</dt><dd>かつお節</dd></span>
</dl>
<div class="faq">
  <dt>ごはんは何回?</dt>
  <dd>1日2回です</dd>
</div>

I ran Lighthouse on this page, then used a small script (summarize.mjs) to extract the audits["definition-list"] entry from the JSON result, along with audits.dlitem, which I cover later.

console
$ npx lighthouse http://localhost:8080/before.html --only-categories=accessibility --output=json --output=html --output-path=./out/before --chrome-flags="--headless=new --no-sandbox" --quiet
$ node summarize.mjs out/before.report.json
lighthouseVersion: 13.6.0  formFactor: mobile  locale: en-US
requestedUrl: http://localhost:8080/before.html
accessibility score: 79
definition-list: score=0 scoreDisplayMode=binary title="`<dl>`'s do not contain only properly-ordered `<dt>` and `<dd>` groups, `<script>`, `<template>` or `<div>` elements."
  <dl class="profile"> | Fix all of the following: dl element has direct children that are not allowed: h2, span
    -> <h2>
    -> <span class="row">
dlitem: score=0 scoreDisplayMode=binary title="Definition list items are not wrapped in `<dl>` elements"

(In practice, I ran this from a small shell script that set CHROME_PATH. I omitted the four flagged <dt> and <dd> lines that follow the dlitem row, and the two lines that show weights and other details.)

For each flagged <dl>, the message "dl element has direct children that are not allowed:" is followed by the names of the elements that are not allowed as direct children of the <dl>. The -> lines below it show the offending child elements. When I ran with --locale=ja, the audit title was in Japanese, but the explanatory text stayed in English.

In the HTML report, the offending children (<h2> and <span class="row">) are listed one by one under the flagged <dl>.

Lighthouse report with the "dl's do not contain only properly-ordered dt and dd groups" item expanded. Under dl class="profile" are an h2 and a span class="row".
The report for the page before the fix. The offending child elements are listed under the dl.

Move the heading out and change the span to a div

Here is the fixed page:

html
<h2>みけのプロフィール</h2>
<dl class="profile">
  <div class="row"><dt>年齢</dt><dd>3さい</dd></div>
  <div class="row"><dt>好物</dt><dd>かつお節</dd></div>
</dl>
<dl class="faq">
  <dt>ごはんは何回?</dt>
  <dd>1日2回です</dd>
</dl>

The heading applies to the whole list, so I moved it outside the <dl>, placing it just before it. For the element that wraps each pair, I changed the <span> to a <div>. According to MDN's explanation of the dl element, the only things allowed directly inside a <dl> are <dt> and <dd> groups (along with <script> and <template>), or a <div> that wraps such a group. MDN presents wrapping in a <div> as a way to add a class to each group, for example to style it.

However, MDN describes the two options as a choice: pairs placed directly next to each other, or pairs wrapped in a <div>. So I wrapped the first pair in a <div> as well, to use the same structure for every pair. I also changed the FAQ's <div> to a <dl>.

I tested the fixed page the same way. Here are the relevant lines:

console
accessibility score: 100
definition-list: score=1 scoreDisplayMode=binary title="`<dl>`'s contain only properly-ordered `<dt>` and `<dd>` groups, `<script>`, `<template>` or `<div>` elements."
dlitem: score=1 scoreDisplayMode=binary title="Definition list items are wrapped in `<dl>` elements"

The score went from 79 to 100. Both audits have a weight of 7, and both failed before the fix.

I also made a page that mixed pairs placed directly next to each other with pairs wrapped in a <div> inside a single <dl>. Lighthouse passed it (100). Passing Lighthouse does not necessarily mean the markup matches the HTML rules, so it is safest to use one structure that follows MDN's explanation.

dt and dd outside a dl are also flagged by dlitem

The page before the fix also failed the other audit, dlitem ("Definition list items are not wrapped in <dl> elements"). In the Japanese report, this title is shown as a Japanese string that means "Definition list items are not wrapped in a <dl> element." This audit is reported from the side of the <dt> and <dd> elements. It listed four <dt> and <dd> elements whose parent is not a <dl>.

console
  <dt> | Fix any of the following: Description list item does not have a <dl> parent element

The four were the two elements of the pair wrapped in the <span>, and the two inside <div class="faq">. Changing the <span> to a <div> and the <div class="faq"> to a <dl> makes both definition-list and dlitem pass at once. In the page fixed in the previous section, both audits passed together.

I used Playwright's ariaSnapshot() to dump the page's accessibility tree (the structure that screen readers read). The output was the same before and after the fix. In both cases, it showed only term and definition pairs such as term: 年齢 and definition: 3さい, with no <dl> or <span> elements. The snapshot does not show the difference, but Lighthouse checks the parent-child relationships in the HTML, so it still reports the problem.

What can and cannot go inside a dl

I also made a separate page for each of the other markup patterns and checked them.

Contents of the <dl> definition-list dlitem Score
Besides the groups, <script>, <template>, a comment, a hidden <p>, and a <span> with aria-hidden="true". Also includes a group with one <dt> and two <dd>, and a group with two <dt> and one <dd> Pass Pass 100
A <p> inside a <dd> Pass Pass 100
Untagged text after a group (好物:かつお節) Fail (#text) Pass 90
A <div> nested inside the <div> that wraps a group Fail (div > div) Fail 79
A <p> placed next to <dt> and <dd> inside the <div> that wraps a group Fail (div > p) Pass 90
A group wrapped in a <div> with role="group" Fail ([role=group]) Fail 84
A group wrapped in a <span> with display: contents Fail (span) Fail 79
Two <dt> and no <dd> Fail Pass 90
A <dd> placed before its <dt> Fail Pass 90

A group with one <dt> and two <dd>, or two <dt> and one <dd>, passed as long as each <dd> came after a <dt>. A <dd> containing a <p> also passed. A <div> wrapping a group was allowed only one level deep. Two levels of <div>, or a <p> placed next to the <dt> and <dd> inside the wrapping <div>, failed. A <div> with role="group" was also not accepted as a wrapper. Removing the box with CSS display: contents does not change the parent-child relationships in the HTML, so the warning remained.

For a list that contains only <dt> elements, or one where a <dd> comes before any <dt>, the explanation changed to "When not empty, element does not have at least one <dt> element followed by at least one <dd> element." In this case, fix the order rather than the element types.

The scores differ because the number of failing audits and the number of audits included in the score differ from page to page. On the page before the fix, 10 weighted audits were counted (total weight 68), and the two weight-7 audits failed, giving 79. On the role="group" page, 13 audits were counted (total weight 89). The same two failed, but the score was 84.

Warning

If you add a role attribute such as role="list" to the <dl>, the definition-list audit stops checking the element. On a page with a <dl role="list"> containing groups wrapped in <span>, definition-list was "not applicable" and was left out of the score. dlitem still failed, and another audit, aria-required-children, also failed with "Element has children which are not allowed: dt, dd". The score was 82. Trying to remove the warning with role adds more warnings.

This behavior comes from the no-role-matches option in the definition-list rule in axe-core 4.14.0, which limits the rule to elements without a role attribute. Lighthouse 13.6.0's source for this audit does not apply its own checks. It relies on the results from axe-core.

​Posted by 86