On The <dl>
143 points
2 hours ago
| 19 comments
| benmyers.dev
| HN
chrismorgan
55 minutes ago
[-]
> <dl aria-label="Ability Scores">

This is incorrect:

1. <dl> has no corresponding (viz. implicit) role, but can be given the role group, list, none or presentation <https://w3c.github.io/html-aria/#el-dl>.

2. You’re only allowed to define aria-label on elements that have a compatible role, implicit or explicit <https://w3c.github.io/html-aria/#docconformance-naming>.

3. aria-label is allowed on all but a handful of roles <https://www.w3.org/TR/wai-aria-1.2/#aria-label>, which in this case knocks out presentation and none, leaving group and list.

4. group doesn’t feel right, list feels acceptable.

In summary: either ditch the aria-label, or add role="list" (meaning also role="listitem" on children).

—⁂—

One thing the article misses is that you can have multiple <dt> in a row too, not just <dd>. The spec has a good example: https://html.spec.whatwg.org/multipage/grouping-content.html...

They’re not name–value pairs, they’re name–value groups.

reply
redmatter
55 seconds ago
[-]
Wow I have never noticed that, thanks for the heads up! Out of curiosity, would you put `role="listitem"` on `<div>` elements that wrap the `<dt>` && `<dd>` elements? It looks like `role="listitem"` is allowed on the `<dt>` element, but that doesn't feel like it would be accurate in the case where multiple `<dt>` elements are grouped together, and I'm not sure if that would mess with how the element is interpreted natively as as term.
reply
jimbosis
56 minutes ago
[-]
The world's first website makes heavy use of <dl>s.

https://info.cern.ch/hypertext/WWW/TheProject.html

https://info.cern.ch/ (A landing page of sorts to give context and orientation about the actual first website.)

reply
captn3m0
1 hour ago
[-]
> Prior to HTML5, this was called a definition list. This is because the <dl> was originally only intended to represent glossaries of terms and their definitions.

TIL I’ve been naming it wrong for a decade.

reply
xp84
36 minutes ago
[-]
I don’t want to check what year html5 was standardized because I think it may be north of a decade ;)
reply
zbentley
15 minutes ago
[-]
> I think it may be north of a decade

Nearly two!

reply
jasonlotito
20 minutes ago
[-]
TIL The name was changed from a definition list.
reply
Demiurge
1 hour ago
[-]
I love DL. I think tables, at least in the past, were misused as DLs even more in the past and the inconvenience of the table markup is even worse than a bunch of divs.
reply
enriquto
1 hour ago
[-]
It's not that inconvenient if you omit unnecessary closing tags:

    <tr>
    <td> first
    <td> second
    <tr>
    <td> what
    <td> ever
I find it simpler and cleaner than any of the markdown table markups
reply
myfonj
29 minutes ago
[-]
Fair point, though /DT and /DD are also optional just like /TH, /TD and /TR are. So in effect, def…scription list could structurally save you one TR for each entry and two "BLE"s:

    <table><tr><th>Term 1<td>Definition 1
           <tr><th>Term 2<td>Definition 2
    </table>
    <dl><dt>Term 1<dd>Definition 1
        <dt>Term 2<dd>Definition 2
    </dl>
reply
debesyla
58 minutes ago
[-]
Isn't markdown table just a bunch of | ?
reply
zufallsheld
56 minutes ago
[-]
That's the problem.
reply
froh
41 minutes ago
[-]
most specifically the problem is that markdown tables don't allow breaking the table row in multiple lines

but then you can always use HTML tables in markdown and Pandoc transforms it just fine

reply
hnlmorg
18 minutes ago
[-]
<br> has worked fine whenever I’ve needed line breaking in markdown tables
reply
jazzypants
27 minutes ago
[-]
Every markdown implementation is supposed to allow inline HTML.
reply
bdcravens
1 hour ago
[-]
You're right, but forcing tables to cosplay as DLs was far from the worst way that tables were abused.
reply
sodapopcan
1 hour ago
[-]
At least <td>s could easily centre things vertically ;)
reply
egeozcan
49 minutes ago
[-]
I always thought the DL as a single row of a table.
reply
simonw
1 hour ago
[-]
Here's a useful note on how well screen readers support DL: https://adrianroselli.com/2025/01/updated-brief-note-on-desc...
reply
cloud-oak
1 hour ago
[-]
The final example of the DnD statt sheet makes me think whether it's legal to nest <dl>s?

I.e. can we do

    <dl>
      <dt>Actions</dt>
      <dd><dl>...</dl></dd>
    </dl>
reply
perilunar
1 hour ago
[-]
reply
myfonj
23 minutes ago
[-]
Plus, when curious about formal syntactic correctness, there is the validator.w3.org [1].

[1] https://validator.w3.org/nu/?showsource=yes&showoutline=yes&...

reply
moron4hire
42 minutes ago
[-]
I do it to render nested JSON objects, for example.
reply
michalc
1 hour ago
[-]
The GOV.UK Design System summary list component is a description list https://design-system.service.gov.uk/components/summary-list...

And... it also uses the wrapper div for styling

reply
9dev
59 minutes ago
[-]
The wrapper div is making me a bit sad. These days, using grid layout, you don’t actually need it in most cases
reply
shermantanktop
49 minutes ago
[-]
The <dl> tag seems to cover a subset of a broad semantic space, but doesn’t easily extend beyond adding another <dd>.

I dunno, I guess I’m a caveman. If it looks right and works (including accessibility) then I figure I’m pursuing something that doesn’t matter a lot.

reply
Finnucane
10 minutes ago
[-]
We've always used this in our ebooks for abbreviation and glossary lists. The problem I've always had is that you need to use a bit of css to make two lined-up columns. I've done it with floats. Now, some ebook readers will support grid and flex-box, which give better results, but the Kindle still does not. Kindle is sort of the IE6 of the ebook world.
reply
rickstanley
2 hours ago
[-]
I've used this a good amount of times, when I coded in front end projects. The first time gave me that satisfying feeling of using the right tool for the job, like completing a puzzle of HTML semantics. I remember JAWS not announcing it correctly in 2018, not sure if it's better now.
reply
wizzwizz4
1 hour ago
[-]
When I checked in 2024 or 2025, Windows Narrator announced it differently in Chrome, Firefox, Edge (Chromium mode) and Edge (IE mode), and none of them worked how I would expect them to. Adrian Roselli's verdict (https://adrianroselli.com/2025/01/updated-brief-note-on-desc...):

> Description list support continues to be generally good (with VoiceOver still the outlier), even if you may not like how it is supported.

You shouldn't try to fix this kind of thing by mangling the HTML, since (1) users tend to be used to their screen reader's quirks, and (2) in situations like these, making it juuuust right in one screen reader is likely to make it incomprehensible in another. But it is important to be aware of these quirks, so you don't accidentally design an interface that relies on less-quirky behaviour.

reply
tln
1 hour ago
[-]
> Admittedly, however, support for the <dl> element is not yet universal.

Wait what? <DL> has been in HTML since.. the first draft in 1993!

I like DL's but they can be challenging to style. This article is using a lot of fixed pixel widths which would break on really small screens or larger data.

reply
3eb7988a1663
8 minutes ago
[-]
Granted, I do not know what I am doing with CSS, but the Character Sheet example seems standard flexible elements?

Some of the extracted CSS chunks

  #statblock{
    box-shadow:0 20px 25px -5px rgba(0,0,0,.1),0 10px 10px -5px rgba(0,0,0,.04);
    font-family:Lato,'Trebuchet MS',sans-serif;
    font-size:85%;
    min-width:50ch;
    max-width:70ch;
    margin-inline:auto;
    background-color:#fffaf0;
    padding-inline:2rem;
    padding-block:1rem
  }
  dl.statblock-bio{
    color:maroon;
    line-height:1.5;
    border-top:5px solid maroon;
    border-bottom:5px solid maroon;
    margin-block:0.75em;
    padding-block:0.75em
  }
  dl.ability-scores{
    min-width:40ch;
    display:flex;
    justify-content:space-around;
    color:maroon
  }
  dl.ability-scores>div{
    text-align:center;
    line-height:1.5
  }
  dl.ability-scores dt{
    font-weight:700
  }
reply
Telemakhos
2 hours ago
[-]
I was a bit surprised to see nested <div>s given as some sort of precursor pattern, when <dl> was part of HTML before 2.0 back in the days of table layout.
reply
phyzix5761
2 hours ago
[-]
I'm curious if the spec actually says you can only wrap it with a div because I like to do semantic html and name my elements specific to my domain.
reply
philo23
2 hours ago
[-]
Yep, I was a little surprised about that too, seem like it is valid though https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/...
reply
wonger_
1 hour ago
[-]
Seems like div is the only recommended wrapper element:

https://html.spec.whatwg.org/multipage/grouping-content.html...

https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/...

EDIT everyone replied at once lol. I'm surprised too about div.

Also, screen reader support: https://a11ysupport.io/tech/html/dl_element

reply
Tomte
2 hours ago
[-]
reply
moron4hire
41 minutes ago
[-]
Custom-named elements are divs.
reply
phyzix5761
5 minutes ago
[-]
They're not as you can see here[1] and here[2]. They both inherit from the HTMLElement interface but div is considered an HTMLDivElement which makes it distinct from a custom element.

<my-element> != <div>

[1] https://developer.mozilla.org/en-US/docs/Web/API/Web_compone...

[2] https://developer.mozilla.org/en-US/docs/Web/API/HTMLDivElem...

reply
jazzypants
18 minutes ago
[-]
Exactly! It cracks me up when people name-check "semantic elements" when it doesn't actually mean anything in that context. Accessibility software doesn't understand the semantics of your custom elements, so there is no benefit in that situation whatsoever. Maybe it's easier for you to read and edit in the future, but that's it.

Somehow, people got convinced that <div> elements are evil and should never be used no matter what. Yes, you should use a more semantic element when it makes sense, but try to remember what that phrase actually means.

reply
phyzix5761
14 minutes ago
[-]
I use it for readability and to express intention and meaning to the reader of my program. In the age of AI, perhaps, we've lost the need for that. But it was much appreciated in times before by those who came upon my code.
reply
turtleyacht
2 hours ago
[-]
Hoped to see CSS for the alternative, where <div> is not nested inside the <dl>. Too used to thinking of div as "layout containers."
reply
gbeardish
1 hour ago
[-]
What about multiple '&lt;dt&gt;' for one or more '&lt;dd&gt;'?
reply
smitty1e
59 minutes ago
[-]
This seems a clear enough win for things that would fit into a simple python dictionary.

Why is it preferred over <table> for laying out columns via a the character attributes at the bottom of TFA?

reply
mockbuild
1 hour ago
[-]
it's on archive html5 .flac 16-bit 44.1kHz no <dl> flag.
reply
jdw64
1 hour ago
[-]
blog looks beautiful. I really wish I had this kind of talent for frontend.
reply
MattRix
1 hour ago
[-]
Good title
reply