[whatwg] Suggest making <dt> and <dd> valid in <ol>
Ian Hickson
ian at hixie.ch
Sun Jul 15 21:31:44 PDT 2012
On Sat, 14 Jul 2012, Ian Yang wrote:
>
> Recently I was involved in a project. One of its pages has a special
> content which is like a "life cycle". There are several stages in the
> cycle, each stage has a term followed by some text describing the term.
> Let's take the life cycle of butterfly for example:
>
> Egg
> A white egg.
>
> Caterpillar
> The egg hatches into a caterpillar. The caterpillar eats and grows a
> tremendous amount.
>
> Pupa
> The caterpillar forms a hard outer shell. Inside the shell, the caterpillar
> changes into a butterfly.
>
> Butterfly
> Butterflies live for only a short time. They will fly, mate, and reproduce.
> The female lays an egg that was fertilized by the male.
>
> By seeing such contents, we usually code it using definition list
> (<dl>). At first, I was thinking the same idea. But then I realized that
> stages in a life cycle should be regarded as ordered contents. So
> ordered list (<ol>) would be more appropriate.
<ol> and <dl> would both be fine here. I'd probably go with <ol>, because
it's a list of states, each of which has a name, rather than a list of
names, but both are reasonable.
With <ol>, I'd probably write:
<ol>
<li><dfn>Egg</dfn>: A white egg.
<li><dfn>Caterpillar</dfn>: The egg hatches...
...and so on.
> If we could make <dt> and <dd> being not restricted to <dl> only, but
> could also exist in <ol>, the problem will be solved perfectly.
It's not clear that there's a problem to be solved. :-)
(Also, there are parsing issues that make changing this area of the spec
be rather fraught with peril.)
On Sat, 14 Jul 2012, Anne van Kesteren wrote:
>
> I would recommend not over-thinking the matter. Otherwise soon you will
> start wrapping your <p>s in <ol>/<li>s too to ensure they stay in the
> correct order.
True!
> Using <dl> for ordered groups is perfectly fine.
>
> (The specification points this out as well: "The order of the list of
> groups, and of the names and values within each group, may be
> significant.")
Indeed.
On Sat, 14 Jul 2012, Jukka K. Korpela wrote:
>
> Indeed. The <ol> element is no more and no less ordered than <ul> or any
> other element. Many HTML tag names are misleading.
It's certainly true that many element names are derived more from
historical accidents than their current semantics, but <ol> and <ul> are
semantically quite different, as the spec describes.
Specifically, <ol> implies that the order of the list cannot be changed
without affecting the meaning of the page, whereas the order in a <ul>
list is merely aesthetic.
> > (The specification points this out as well: "The order of the list of
> > groups, and of the names and values within each group, may be
> > significant.")
>
> That's actually a questionable statement there, since it may make the
> [reader] ask whether the order of sub-elements is *generally*
> significant.
That is a good question to ask oneself.
> It's as questionable as it would be to write "The order of successive p
> elements may be significant" or "The order of successive section
> elements may be significant".
They indeed _are_ significant. The spec doesn't mention this, though,
because it's blatently obvious and nobody in their right mind will
question it. :-)
With <dl>, we do get people asking whether it's ok to have the order
matter, so having an explicit statement in the spec allowing it is useful.
(Witness this very thread for such an example.)
On Sat, 14 Jul 2012, Ian Yang wrote:
>
> So based on the <ul> and the <ol>, we could have unordered definition
> list (<udl>) and ordered definition list (<odl>).
I don't really understand what problem this solves.
On Sat, 14 Jul 2012, Ian Yang wrote:
> 2012/7/14 Jukka K. Korpela <jkorpela at cs.tut.fi>
> >
> > Indeed. The <ol> element is no more and no less ordered than <ul> or
> > any other element. Many HTML tag names are misleading.
>
> That's interesting. If <ol> is no more and no less ordered than <ul>,
> what's the purpose of its introduction? Could you provide detailed
> explanations or examples? Thanks.
Jukka is incorrect in his statement. The difference between <ol> and <ul>
is specifically that the order of elements in <ol> matters and the order
of elements in <ul> does not.
>From the spec:
# The ol element represents a list of items, where the items have been
# intentionally ordered, such that changing the order would change the
# meaning of the document.
# The ul element represents a list of items, where the order of the items
# is not important -- that is, where changing the order would not
# materially change the meaning of the document.
There are examples in the two sections that illustrate the quite serious
semantic difference between the two.
On Sat, 14 Jul 2012, Jukka K. Korpela wrote:
>
> The real purposes, in the dawn of HTML, were that <ol> and <ul>
> correspond to numbered and bulleted lists, respectively, reflecting two
> very common concepts in word processors. This is how they have been
> used, though some authors have started overusing <ul> for thinks like
> lists of links even when they specifically don't want them to appear as
> bulleted.
Certainly that is, to a first approximation, a good way of thinking of the
difference between the two.
Of course, in many contexts there are no bullets or numbers, so this
simplification is not the whole story. For example, when reading a list,
even an unordered list, using speech synthesis, it may be useful for
navigation purposes to have all lists be numbered. This does not mean
there is no difference between <ul> and <ol>, as the examples in the spec
illustrate.
> Even W3C specifications, in their markup, switch to <ul> in the midst of
> hierarchy when they want bullets and not numbers.
W3C specifications are hardly what I would refer to as the epitome of good
Web design, so I'm not sure I'd draw any conclusions from that!
> HTML5 tries to stick to the theoretical idea of "ordered" vs.
> "unordered" list, but it does not really change anything, and it is not
> supposed to change anything - any <ul> will still be rendered in the
> order written.
Not necessarily. That depends on the UA.
> More on this:
> http://www.cs.tut.fi/~jkorpela/html/ul-ol.html
The example in that document, from the old HTML4 specification, is a
perfect example of incorrect usage of <ul>.
In general, I would recommend referring to the contemporary specification
for more precise information on the elements' semantics and usage.
On Sun, 15 Jul 2012, Jukka K. Korpela wrote:
> 2012-07-15 17:40, Ian Yang wrote:
> >
> > As a coder, personally I don't care how browsers render them by
> > default.
>
> You should. Check out the Usual CSS Caveats.
On the contrary. Ian is correct to rely on the meaning of the language
rather than its default rendering in one user agent or another.
On Mon, 16 Jul 2012, Ian Yang wrote:
>
> Sorry, I still don't get it. <ul> means unordered list; <ol> means
> ordered list. They are quite different, aren't they?
They are indeed quite different.
> Imo, <ul> means the order of the items is unimportant, not browsers can
> render the items in any order.
>
> If there were a browser which wants to render the items of <ul> in any
> order, okay, it may do that. Anyway, that's not my main concern.
That is an appropriate use of HTML. :-)
On Sat, 14 Jul 2012, Ian Yang wrote:
>
> Thanks for the info about the spec saying in <dl> the order of the list
> of groups *may* be significant. However, what it says means a <dl>
> itself is unable to tell whether its contents are unordered or ordered,
> and we have to judge that by ourselves.
Well, what it means is that a user agent can't randomly reorder a <dl>'s
contents, as that would violate the rule that its rendering must
faithfully represent the page's semantics. (The spec relies on this in
several places to mark up English-prose equivalents of "switch statements"
in its algorithms, for example.)
> Comparing to <ul> and <ol> which themselves are able to tell whether
> their contents are unordered and ordered, the <dl> itself being unable
> to do that is, imho, disappointing.
It's something we could add, but it's not clear that there's a compelling
need for it. What is the use case for knowing that a <dl>'s contents can
be arbitrarily reordered?
--
Ian Hickson U+1047E )\._.,--....,'``. fL
http://ln.hixie.ch/ U+263A /, _.. \ _\ ;`._ ,.
Things that are impossible just take longer. `._.-(,_..'--(,_..'`-.;.'
More information about the whatwg
mailing list