Repository navigation
Description
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
zcorpan commentedon Oct 20, 2016
dtandddhave optional end tags, which doesn't interact well with wrapping in a new element.Wrapping in
liworks fine parsing-wise, even when you omit the[doesn't work so well either parsing-wise; if you omit all end tags then the inner</dd>/</dt>/</li>tags.ligets nested in theddinstead of becoming a sibling of the previousli.] 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
divas 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").Crissov commentedon Oct 20, 2016
Indeed,
liwould work (better) if its end tag was not optional when insidedl.DOM viewer of all variants from above and more
domenic commentedon Oct 20, 2016
divsounds pretty great to me.tabatkins commentedon Oct 20, 2016
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.
Crissov commentedon Oct 20, 2016
divis better thandibecause 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).annevk commentedon Oct 21, 2016
I have been wanting this for a long time. Kudos to y'all for coming up with something that might fly.
zcorpan commentedon Oct 21, 2016
Summoning @sideshowbarker
I'm thinking we make the content model as strict and simple as possible: either
dlcontains onlydtandddchildren like today, or it contains onlydivchildren, each of which must contain exactly one (dt+,dd+) group. So emptydivs not allowed, and arbitrary grouping or nesteddivs also not allowed.No change to the parser, rendering, or other UA requirements; this should only affect document conformance.
Crissov commentedon Oct 21, 2016
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:
<ul><li><dt>term <dd>definition</li></ul>– requires special-casingdt/ddcontent ofli, should work the same forol<dl><li><dt>term <dd>definition</li></dl>– requires different rules forliinsidedlthan insideol/ul<dl><div><dt>term <dd>definition</div></dl>– only requires changes to the content model ofdl, may have existing use<dl><entry><dt>term <dd>definition</entry></dl>– this isdi, i.e. a new wrapping element<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<list><div><dt>term <dd>definition</div></list>– alternative for 3., otherwise like 5.<list><entry><dt>term <dd>definition</entry></list>– alternative for 4., otherwise like 5.Semantically, all variants can be argued for well enough.
zcorpan commentedon Oct 21, 2016
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 ofdlcould also have other implications like regressing usability for people using accessibility tools; suddenly they can't skip over adlelement, for example.And
lididn'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
liI got extra "bullet" or "list item"; a newlistelement affected navigation in ChromeVox.More testing in other screen reader/browser/platform combinations is welcome, but so far I think
divis most promising.sideshowbarker commentedon Oct 21, 2016
As far as any proposal for changing the
dlcontent 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
divoption—if we spec the doc-conformance requirements in the way described in #1937 (comment) so that, e.g, adivthat’s a child of adlmust contain exactly one (dt+,dd+) group.Certainly it’s practical to implement the checking for that in the validator
So I like the
divoption.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:
Allow <div> around each <dt><dd> group in <dl>
zcorpan commentedon Oct 21, 2016
I've prepared a PR for spec change at #1945
Test cases for conformance checkers at web-platform-tests/wpt#4053
66 remaining items
patrickdark commentedon Dec 6, 2016
@zcorpan: I think a new
dgroup(or similardg,di,dli, etc) element would be less confusing than re-use of thedivelement 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
dtelements reads "Adtelement's end tag can be omitted if thedtelement is immediately followed by anotherdtelement or addelement." Append "and the element is not the child of adgroupelement" to the end of the sentence.Do likewise for
ddelements.The only browser implementation change needed is a UA stylesheet update to make it a block-level element as was the case with the
hgroupelement, if I'm not mistaken.zcorpan commentedon Dec 6, 2016
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.
patrickdark commentedon Dec 6, 2016
@zcorpan:
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.
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.
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
spanelement within a paragraph element. If one doesn't write correct code, they don't get correct results.domenic commentedon Dec 6, 2016
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.
ianthedev commentedon Dec 7, 2016
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.
zcorpan commentedon Dec 7, 2016
@patrickdark
https://github.com/html5lib/html5lib-python
dl.html
test-serialize.py
zcorpan commentedon Dec 7, 2016
@Ian-Y
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.
ianthedev commentedon Dec 7, 2016
@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?patrickdark commentedon Dec 9, 2016
@zcorpan
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 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
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
All the more reason to do the right thing and not shoehorn the
divelement.But alas, I guess we're going to be stuck writing non-straight-forward
dl > divand:not(dl) > divselectors forever just like we're already stuck writing annoyances likeruby > :not(rp):not(rt):not(ruby)because someone decided that therbelement is evil.chharvey commentedon Apr 9, 2017
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 anddds together. In fact, I definitely agree that the content model ofdlshould 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 choosingdiv(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-ddgroups using Microdata and ARIA and other global attributes.In this example, one could argue that
ulorolwould be better suited for this list of dates, however we would then not be able to usedtandddto 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, surelydtandddare better than any alternatives. Inside aulorol, eachliwould 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
divas 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
dgordior something else. I think in this situation thelielement is perfect. The spec says it “represents a list item,” which is more or less its purpose here in adllist. In the current spec, the content model ofdivis dependent on its context (whether it is a child ofdlor not), so I don’t see any reason why the same can’t be done forli.If
liwere 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
lito be an acceptable child of all three lists,ol,ul, anddl?zcorpan commentedon Apr 10, 2017
Mixing is invalid.
You can do this with
div.lihas the most problems, see #1937 (comment)chharvey commentedon Apr 11, 2017
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 ofdt-ddsets, etc. Since we need to add semantics anyway it doesn’t make sense to use a "non-semantic" element. So really, anything is better thandiv, andliis the best choice.li:</li>end tags can still be omitted as long as theliis followed by anotherlielement or reaches the end of the parentdlelement. This is exactly the same requirement forlichildren ofolandulelements.dl > liin the spec won’t break current CSS.liitems of adlshouldn’t be numbered or bulleted (or should they??), but this goes back to the second point above: the default styling ofdlshould havelist-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 > divjust seems like a hack, and encouraging authors to do it is subjectively wrong.zcorpan commentedon Apr 11, 2017
If you get all implementations to change such that the problems with
liare 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.
inoas commentedon Sep 9, 2017
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.)
Allow <div> around each <dt><dd> group in <dl> (whatwg#1945)