Skip to content

Reconsider FAQ: <di>, <div> or <li> wrapping <dt> and <dd> #1937

Closed

Description

@Crissov

Explicitly grouping dt and dd together has been proposed so often that it’s featured in the Rationale and has been in the FAQ since 2008, getting further explained in 2010.

This is a styling problem and should be fixed in CSS. There's no reason to add a grouping element to HTML, as the semantics are already unambiguous.

There will be no CSS pseudo-element ::wrap in the forseeable future, see w3c/csswg-drafts#588. I believe it’s therefore worth to reevaluate the use cases and review the FAQ entry.

Current state

The parsing rules for dl are quite clear, but even if browsers implemented them perfectly, there’d still be no way to take advantage of the structure in CSS.

<dl>
  <dt>term <dt>alias <dd>definition
  <dt>term <dd>definition <dd>alternate definition
  <dt>term <dt>alias <dd>definition <dd>alternate definition
</dl>

di Wrapper

This has also been called dli. It has all the problems of any new element type, and some more.

<dl>
  <di><dt>term <dt>alias <dd>definition</di>
  <di><dt>term <dd>definition <dd>alternate definition</di>
  <di><dt>term <dt>alias <dd>definition <dd>alternate definition</di>
</dl>

li Wrapper

It has all the problems of using existing elements in places where they were not supposed to occur previously, which can be quite unexpected.

<dl>
  <li><dt>term <dt>alias <dd>definition</li>
  <li><dt>term <dd>definition <dd>alternate definition</li>
  <li><dt>term <dt>alias <dd>definition <dd>alternate definition</li>
</dl>

dt/dd in li

It may be worth exploring whether ditching dl has better backwards compatibility than changing it.

<ul>
  <li><dt>term <dt>alias <dd>definition</li>
  <li><dt>term <dd>definition <dd>alternate definition</li>
  <li><dt>term <dt>alias <dd>definition <dd>alternate definition</li>
</ul>

Generic list element

<list>
  <lh>header
  <dt>term <dd>definition
  <di><dt>term <dt>alias <dd>definition</di>
  <di><dt>term <dd>definition <dd>alternate definition</di>
  <di><dt>term <dt>alias <dd>definition <dd>alternate definition</di>
  <li>item
</list>

Activity

  1. zcorpan commented on Oct 20, 2016

    @zcorpan
    Member

    dt and dd have optional end tags, which doesn't interact well with wrapping in a new element.

    Wrapping in li works fine parsing-wise, even when you omit the </dd>/</dt>/</li> tags. [doesn't work so well either parsing-wise; if you omit all end tags then the inner li gets nested in the dd instead of becoming a sibling of the previous li.] The default style would give you bullets, which doesn't seem great. Also nested lists get different style for the bullets today, but that would not work without new more complicated rules to the UA stylesheet.

    How about allowing div as the wrapper? It has no problems parsing-wise (the end tag is required), it does not alter the default styling, and it seems like it has the right semantic ("represents its children").

  2. Crissov commented on Oct 20, 2016

    @Crissov
    Author

    Indeed, li would work (better) if its end tag was not optional when inside dl.

    DOM viewer of all variants from above and more

  3. domenic commented on Oct 20, 2016

    @domenic
    Member

    div sounds pretty great to me.

  4. tabatkins commented on Oct 20, 2016

    @tabatkins
    Contributor

    I'm 👍 to DIV. I also really like LI if it auto-closes better and gets some UA styling, but that's a lot of effort.

  5. Crissov commented on Oct 20, 2016

    @Crissov
    Author

    div is better than di because the latter looks like a typo of the former and sometimes actually will be one. If it was to be a new element type, there are several possibilities, e.g. wrap, item, entry, def, desc (SVG conflict).

  6. annevk commented on Oct 21, 2016

    @annevk
    Member

    I have been wanting this for a long time. Kudos to y'all for coming up with something that might fly.

  7. zcorpan commented on Oct 21, 2016

    @zcorpan
    Member

    Summoning @sideshowbarker

    I'm thinking we make the content model as strict and simple as possible: either dl contains only dt and dd children like today, or it contains only div children, each of which must contain exactly one (dt+, dd+) group. So empty divs not allowed, and arbitrary grouping or nested divs also not allowed.

    No change to the parser, rendering, or other UA requirements; this should only affect document conformance.

  8. Crissov commented on Oct 21, 2016

    @Crissov
    Author

    Spec-wise, it seems there is no way around a wrapping element with mandatory end tag. The deciding question probably is which one (new or reused) provides the best backwards compatibility:

    1. <ul><li><dt>term <dd>definition</li></ul> – requires special-casing dt/dd content of li, should work the same for ol
    2. <dl><li><dt>term <dd>definition</li></dl> – requires different rules for li inside dl than inside ol/ul
    3. <dl><div><dt>term <dd>definition</div></dl> – only requires changes to the content model of dl, may have existing use
    4. <dl><entry><dt>term <dd>definition</entry></dl> – this is di, i.e. a new wrapping element
    5. <list><li><dt>term <dd>definition</li></list> – alternative for 1. or 2., if none of the above degrades gracefully; could allow other features like list headers/captions
    6. <list><div><dt>term <dd>definition</div></list> – alternative for 3., otherwise like 5.
    7. <list><entry><dt>term <dd>definition</entry></list> – alternative for 4., otherwise like 5.

    Semantically, all variants can be argued for well enough.

  9. zcorpan commented on Oct 21, 2016

    @zcorpan
    Member

    I think we shouldn't mint a new element, as I said, it doesn't interact well with omitting end tags of dt/dd. So that rules out 4, 5, 6, 7. A new element instead of dl could also have other implications like regressing usability for people using accessibility tools; suddenly they can't skip over a dl element, for example.

    And li didn't work well in terms of parsing and styling, so that rules out 1 and 2. Just saying that </li> is required in this context is not so helpful because tools probably exist that assume it is optional anywhere, and will just strip them out.

    That leaves 3. I can't think of any practical problems with it. As far as accessibility tools go, I've quickly tested VoiceOver with Safari and ChromeVox with Chrome (both on Mac OS X), and there was no difference for 3. Since the stated problem is about styling, I think getting no difference in accessibility tools should be a goal. With li I got extra "bullet" or "list item"; a new list element affected navigation in ChromeVox.

    More testing in other screen reader/browser/platform combinations is welcome, but so far I think div is most promising.

  10. sideshowbarker commented on Oct 21, 2016

    @sideshowbarker
    Member

    As far as any proposal for changing the dl content model at all, without adding any new elements, from a conformance-checker POV the main possible problem I see is the general problem that when we change or relax existing doc-conformance requirements, it may inadvertently cause authors to miss some genuine mistake the checker otherwise would have been able to help them catch.

    But I think the using-an-existing-element option that would carry the least risk of that problem is the div option—if we spec the doc-conformance requirements in the way described in #1937 (comment) so that, e.g, a div that’s a child of a dl must contain exactly one (dt+, dd+) group.

    Certainly it’s practical to implement the checking for that in the validator

    So I like the div option.

    As far as the option of instead minting a new element, from a conformance-checker POV: while it doesn’t carry the risk that I think a repurpose-an-existing-element option does of possibly causing authors to miss genuine mistakes the checker would otherwise help them catch, IMHO it’s not the right option in this case—for the same reasons @zcorpan gives but also because:

    • For the sake of authors I think we should always be extremely conservative about adding new elements, and only do it when there’s a really compelling need and no other appropriate markup options to solve the problem the new element would be intended to solve.
    • It seems to me in the many years during which we’ve discussed this problem/use-case, implementors have shown relatively little interest in it, and so it also seems to me that they would especially show little interest in adding a new element to solve the problem. And of course we can’t end up getting implementor support for it, we will have just been wasting our time.
  11. added a commit that references this issue on Oct 21, 2016
    727674c
  12. zcorpan commented on Oct 21, 2016

    @zcorpan
    Member

    I've prepared a PR for spec change at #1945
    Test cases for conformance checkers at web-platform-tests/wpt#4053

  13. self-assigned this
    on Oct 21, 2016
  14. 66 remaining items

  15. patrickdark commented on Dec 6, 2016

    @patrickdark

    @zcorpan: I think a new dgroup (or similar dg, di, dli, etc) element would be less confusing than re-use of the div element in consideration of @inoas' post at #1937 (comment).

    I don't see why this requires parser changes either; just change the "Tag omission in text/html" text in the spec. See https://html.spec.whatwg.org/multipage/semantics.html#the-dt-element.

    Right now, the aforementioned text for dt elements reads "A dt element's end tag can be omitted if the dt element is immediately followed by another dt element or a dd element." Append "and the element is not the child of a dgroup element" to the end of the sentence.

    Do likewise for dd elements.

    The only browser implementation change needed is a UA stylesheet update to make it a block-level element as was the case with the hgroup element, if I'm not mistaken.

  16. zcorpan commented on Dec 6, 2016

    @zcorpan
    Member

    Saying that the end tag is required in this context is not so helpful because tools probably exist that assume it is optional anywhere, and will just strip them out.

    If the end tag is optional sometimes and sometimes not, I don't think it would be less confusing overall. Some developers are likely to run into accidentally violating the rule and end up with a weird DOM and be confused.

  17. patrickdark commented on Dec 6, 2016

    @patrickdark

    @zcorpan:

    Saying that the end tag is required in this context is not so helpful because tools probably exist that assume it is optional anywhere, and will just strip them out.

    I'd suggest that hypothetical tools that perform tag-stripping should not be considered relevant as these are (A) hypothetical and (B) have no bearing on the long-term use of HTML, which is more important.

    If the end tag is optional sometimes and sometimes not, I don't think it would be less confusing overall.

    In contexts where optional end tags are always used, this is a moot point.

    I think tag omission should treated as a legacy issue rather than a feature that other features must yield to. In this case, a long-term feature is being created and it seems to be designed with the principle that tag omissibility is something that should be preserved.

    Some developers are likely to run into accidentally violating the rule and end up with a weird DOM and be confused.

    In an HTML spec amended as proposed, what you'd be describing is a syntax error. It's no different than an author ending up with an unexpected DOM because they forgot to terminate a span element within a paragraph element. If one doesn't write correct code, they don't get correct results.

  18. domenic commented on Dec 6, 2016

    @domenic
    Member

    I think tag omission should treated as a legacy issue rather than a feature that other features must yield to.

    Tag omission is a crucial part of writing modern, clean HTML; several major style guides mandate it. It's one of HTML's greatest features in my opinion. Some may dislike it, but we certainly have no intention of treating it as a legacy issue.

  19. ianthedev commented on Dec 7, 2016

    @ianthedev

    Maybe a consensus is needed from the community on tag omission. While some may like it and think it makes HTML clean, I personally think it causes inconsistency among content-wrapping tags and makes HTML less careful. I myself always avoid using tag omission.

  20. zcorpan commented on Dec 7, 2016

    @zcorpan
    Member

    @patrickdark

    I'd suggest that hypothetical tools ...

    https://github.com/html5lib/html5lib-python

    dl.html

    <dl><dgroup><dt>hello</dt><dd>hello</dd></dgroup></dl>

    test-serialize.py

    import html5lib
    f = open("dl.html")
    tree = html5lib.parse(f)
    str = html5lib.serialize(tree)
    print str
    $ python test-serialize.py 
    <dl><dgroup><dt>hello<dd>hello</dgroup></dl>
    
  21. zcorpan commented on Dec 7, 2016

    @zcorpan
    Member

    @Ian-Y

    Maybe a consensus is needed from the community on tag omission.

    It seems pretty clear to me that there is no consensus on optional end tags in the community. As @domenic said, there are style guides that recommend it (e.g., this one), and just in this thread we see people with differing opinions. Some people like it, some people don't.

    But consensus is not necessary to make a decision in the WHATWG. See the FAQ and an old post by Hixie.

  22. ianthedev commented on Dec 7, 2016

    @ianthedev

    @zcorpan Thanks. I see.

    @patrickdark and all other who are interested in a new <dgroup> tag, I created a thread on WICG discussing about using <dt> and <dd> inside <ul> and <ol> instead. Here is the thread: Is the design of <dl> tag flawed?

  23. patrickdark commented on Dec 9, 2016

    @patrickdark

    @zcorpan

    test-serialize.py

    It's an improvement that we're not dealing in hypothetical tools.

    I see no reason why the tool can't be fixed, however. It also seems that the tool is in a beta state—which suggests a good time for a fix—and two of its three libraries are dead, so I'm not sure how relevant it is.

    Authors who have deployed this tool can use existing workarounds for lack of a description list grouping element until the tool is updated. (I'm not familiar with Python, but I'm guessing the fix would be relatively trivial too given that this tool seems to be based on an XML tree generator where tags are mandatory.)

    @domenic

    Tag omission is a crucial part of writing modern, clean HTML [...]. It's one of HTML's greatest features in my opinion. Some may dislike it, but we certainly have no intention of treating it as a legacy issue.

    Tag omission is an optional—not crucial—part of HTML. I write code in XHTML where this shortcut is simply disallowed and haven't missed it.

    Tag omission does allow one to write less verbose code, but this comes at the expense of code clarity. That we're even having this discussion about tag omission producing unpredictable DOMs using conventional source code structures seems to be proof of that.

    (It also seems to be proof that the parsing design is fundamentally flawed and moreso if tag omission is a feature to be added to future elements, but since parsing changes are off the table...)

    @domenic @zcorpan

    there are style guides that recommend [tag omission]

    You've pointed out a singular example that "recommends" tag omission after said style guide has declared that part of itself "optional". Further, it explicitly acknowledges that its optional recommendation is not part orthodox Web development instruction.

    Further, this singular guide doesn't appear to be attributed to any individuals or organizations—despite its implied association with Google—and is written in a custom XML syntax instead of HTML, so I'm not sure why it should be held as a credible authority for determining the future evolution of HTML.

    @zcorpan

    But consensus is not necessary to make a decision in the WHATWG.

    All the more reason to do the right thing and not shoehorn the div element.

    But alas, I guess we're going to be stuck writing non-straight-forward dl > div and :not(dl) > div selectors forever just like we're already stuck writing annoyances like ruby > :not(rp):not(rt):not(ruby) because someone decided that the rb element is evil.

  24. chharvey commented on Apr 9, 2017

    @chharvey

    I’d like to add my voice to the discussion, although I might not be adding anything new. I know others have already expressed similar views, and I also know other others will disagree. But I want to cast my vote.

    I like the idea of repurposing/extending the <li> element to be allowed as children of <dl> elements, just as the <div> has been done currently.

    “div is non-semantic” is not good enough

    I understand the reasoning behind choosing div: there is no need to put in an extra ‘semantic’ element because the groups are already determined implicitly. However, I don’t think this is a very good argument.

    First of all, the implicit grouping model goes out the window when we are now using an explicit element to group dts and dds together. In fact, I definitely agree that the content model of dl should be either 0 or more implicit groups or 1 or more ‹whatever› elements. Mixing these kinds of groups would be a nightmare. Using only ‹whatever› elements eliminates the need for the implicit grouping model, which is the whole reason for choosing div (as opposed to a more ‘semantic’ element) to do the wrapping.

    Now, the first point is moot, because more importantly, there is indeed a reason for needing a wrapping element in the first place: to add semantics. I’m not talking about styling issues, which can & should be solved with CSS; I’m talking about markup issues, such as how to mark up dt-dd groups using Microdata and ARIA and other global attributes.

    <h1>Important Dates:</h1>
    <dl>
      <li itemscope="" itemtype="http://schema.org/Event">
        <dt><time datetime="2015-10-12" itemprop="startDate">Oct 12, 2015</time></dt>
        <dd itemprop="name">Topic Due</dd>
      </li>
      <li itemscope="" itemtype="http://schema.org/Event">
        <dt><time datetime="2015-11-12" itemprop="startDate">Nov 12, 2015</time></dt>
        <dd itemprop="name">Draft Due</dd>
      </li>
      <li itemscope="" itemtype="http://schema.org/Event">
        <dt><time datetime="2015-12-12" itemprop="startDate">Dec 12, 2015</time></dt>
        <dd itemprop="name">Final Paper Due</dd>
      </li>
    </dl>

    In this example, one could argue that ul or ol would be better suited for this list of dates, however we would then not be able to use dt and dd to mark up the date-description pairs, which poses the question, what elements should be used for those pairs? Since the items all have parallel structures, surely dt and dd are better than any alternatives. Inside a ul or ol, each li would be free-form, allowing any flow content, but in this example we have a stricter structure.

    Side note: I know this isn’t really a convincing point, but I like to think of div as a ‘DIVision’ of a document, and I prefer to use it only as a last resort, when no other element will suffice.

    introducing a new element is cumbersome

    I agree with the many posts in this discussion about the costs of adding a new element, be it dg or di or something else. I think in this situation the li element is perfect. The spec says it “represents a list item,” which is more or less its purpose here in a dl list. In the current spec, the content model of div is dependent on its context (whether it is a child of dl or not), so I don’t see any reason why the same can’t be done for li.

    If li were extended in this manner, I don’t think the rules for any element’s closing tag omission would need to change (although I prefer to always close all my tags anyway). The closing </li> tag may be omitted if followed by another <li> opening tag or by a </dl> closing tag (its parent); the closing </dt> tag may be omitted if followed by a <dt> or <dd> opening tag, and the closing </dd> tag may be omitted if followed by a <dt> or <dd> opening tag, or by an </li> closing tag (its parent).

    Incidentally, how fitting would it be for an li to be an acceptable child of all three lists, ol, ul, and dl?

  25. zcorpan commented on Apr 10, 2017

    @zcorpan
    Member

    Mixing these kinds of groups would be a nightmare.

    Mixing is invalid.

    how to mark up dt-dd groups using Microdata and ARIA and other global attributes.

    You can do this with div.

    I think in this situation the li element is perfect.

    li has the most problems, see #1937 (comment)

  26. chharvey commented on Apr 11, 2017

    @chharvey
    1. rightfully so, which is why I said I agreed with that part of the content model.
    2. :tongue-in-cheek response: you can also do it with section, but you don’t see that written in the spec! … More seriously though, my point was that we needed a reason for a wrapping tag in the first place, which is to add semantics—Microdata, ARIA, the grouping of dt-dd sets, etc. Since we need to add semantics anyway it doesn’t make sense to use a "non-semantic" element. So really, anything is better than div, and li is the best choice.
    3. Regarding the problems with li:
    • The </li> end tags can still be omitted as long as the li is followed by another li element or reaches the end of the parent dl element. This is exactly the same requirement for li children of ol and ul elements.
    • The default styling shouldn’t be an issue. Browser default stylesheets can (and should) be updated when the spec is updated, but even if not, author CSS can fix the styling. This feature would also be backwards-compatible, i.e. allowing dl > li in the spec won’t break current CSS.
    • I can’t speak to AT and I’m not sure what you mean by “changed,” so I’ll leave that one alone.
    • The numbering issue seems like a bug. The li items of a dl shouldn’t be numbered or bulleted (or should they??), but this goes back to the second point above: the default styling of dl should have list-style: none, and this can be fixed.

    I understand your reasons for not wanting li, but I think the benefits in the long run will outweigh the costs in the short run. This community has a real opportunity here to make lasting change for the better. If done properly, tools like browsers, parsers, and assistive technology will conform. In fact, they should conform to stay ahead in the game of evolution. Tools that don't constantly update and conform to specifications will fall behind and be overtaken by better, smarter tools. Just look what happened to IE.

    I think it comes across as near-sighted to make a decision based on the way things currently are and how today’s tools work at this time, in fear that a change will cause one of them to break. I get the whole pave the cowpaths concept but allowing dl > div just seems like a hack, and encouraging authors to do it is subjectively wrong.

  27. zcorpan commented on Apr 11, 2017

    @zcorpan
    Member

    If you get all implementations to change such that the problems with li are gone, I'm happy to change the spec. But the spec doesn't have any power to make everyone conform just because we wish so. There has to be interest from implementors to change or we're just wasting time and the spec will be a work of fiction.

    #1937 (comment) demonstrates what the parsing problem is.

  28. inoas commented on Sep 9, 2017

    @inoas

    Now this is just logical but still bad: #2007 (comment) - why would divs work here but not there? I can see the point. But the solution is to not have a div tag but be patient with browser vendors to implement a or tag. There is no need to hurry on this one and it can easily take 3 years and almost no harm will be done because the addition of dt/dd grouping is really a minor feature (compared to such things as http2, webasm, fetch or push/preload etc.)

  29. added a commit that references this issue on Jan 8, 2019
    a7e9222
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions