2

I am writing the HTML for the Terms of Service page. I decided to use the ol element and the section element in consideration of the following two items.

  1. Each item must be guaranteed in order
  2. Each part can be cut out as a section

ol {
  list-style: none;
}
<ol>
  <li>
    <section>
      <h1>1.</h1>
    </section>
  </li>
  <li>
    <section>
      <h1>2.</h1>
    </section>
  </li>
  <li>
    <section>
      <h1>3.</h1>
    </section>
  </li>
</ol>

However, it was reviewed by an acquaintance to change it to only the section element. He said that if you write only the section element, the order is guaranteed.

<section>
  <h1>1.</h1>
</section>
<section>
  <h1>2.</h1>
</section>
<section>
  <h1>3.</h1>
</section>

However, I (and the reviewer) did not find any basis for it in the HTML Standard.

Question

  1. Does the section element alone guarantee that their order matters?

  2. Combining list and section elements is valid, but does this give a semantically inappropriate interpretation as "Terms of Service" page's markup?

e4opy
  • 21
  • 2
  • You are focussing on the wrong question. If it were a matter of order, you would be debating whether to use ol or ul. The question you should be asking is "is my content a *list*?". Since you don't provide your content, we can't judge that, but a red flag is that you've set the list style to "none". That's a big clue that you don't really regard the content as a list. – Alohci Apr 09 '20 at 07:06
  • @Alohci It has a structure similar to SO's [Terms of Service](https://stackoverflow.com/legal/terms-of-service). I thought the question that "is it a list" was abstract because it depends on how each person perceives the list. / If the `section` element doesn't have semantics to guarantee order, we know it's appropriate to represent it with a `ol` element as a list and unorderable. – e4opy Apr 10 '20 at 05:27

2 Answers2

1

Short Answer

He is right, no need for a list here.

Long Answer

Provided you do not change the order with CSS, items will be displayed (and read in a screen reader) in the order they are within the DOM.

So as long as you aren't using any positioning on the section elements that would interfere with this (i.e. position: absolute) and you don't change the order with tabindex="1", tabindex="2" etc. you will be fine.

What you were doing is valid HTML for future reference: the li element uses the flow content content model, as such it can contain any of the items listed on this page

One thing to consider is your use of <h1> within those sections. Although this is technically valid HTML, this will be changing back to the "one <h1> per page" rule soon, it is also highly recommended to do this for screen reader users as they still are not used to the multiple <h1> rule. Change these to <h2> or whatever is appropriate.

If you do this there is no benefit to adding an ordered list (for accessibility at least).

Community
  • 1
  • 1
GrahamTheDev
  • 22,724
  • 2
  • 32
  • 64
  • Sure, the order in the document tree does not change, but is it semantically the same as "this must not change order"? If so, the `ul` and `ol` elements have the same meaning. – e4opy Apr 10 '20 at 05:28
  • All an ordered list does is to add meaning that these items have a hierarchy, it does not guarantee that things are in the right order any more than using `div`s in the correct order in the HTML. https://jsfiddle.net/8a9x5zqn/ is a very crude example, the items will still get read by a screen reader in the order they are in the DOM but appear differently to sighted users. There is no 'this must not change order' within HTML, it is up to you to ensure you do not break the order with your CSS. Order in DOM is all that matters if your CSS does not interfere. – GrahamTheDev Apr 10 '20 at 12:34
0

According to the spec nothing suggests that you cannot use the section tag inside an ol.

The section element represents a generic section of a document or application. A section, in this context, is a thematic grouping of content, typically with a heading.

Examples of sections would be chapters, the various tabbed pages in a tabbed dialog box, or the numbered sections of a thesis. A Web site's home page could be split into sections for an introduction, news items, and contact information.

Reading this your usage of section inside an ol seems to be fine.Besides using the w3.org's HTML5 validator does not give any errors. I would take this with a grain of salt. And according to MDN's usage notes

Usage notes

  • Each should be identified, typically by including a heading (- element) as a child of the element.
  • If it makes sense to separately syndicate the content of a element, use an element instead.
  • Do not use the element as a generic container; this is what is for, especially when the sectioning is only for styling purposes. A rule of thumb is that a section should logically appear in the outline of a document.

To your first question, yes the section element alone will guarantee that their order matters. According to this

The section element is a generic semantic element, that can be used to combine portions of a document together into discrete units that are related in some way. For example, the section element may create items inside an outline of a document, or divide page content into related pieces (like an Introduction) followed by some background information on the topic.

Some examples of usage are given following. The section element can be applied to each individual section of a tab switcher or content slider (if an unordered list is not needed). The section element can also divide a lengthy "terms and conditions" (or similar) page into numbered sections. Furthermore, section elements can divide the different sections of a one-page website or portfolio. A common use offline could be to denote the chapter of a book.

This does indicate that the section item can be used to denote order/flow of a document. Which I think would guarantee that the order matters.

reference - HTML5, <section> inside unordered list

Don’t worry too much about the semantic considerations — they’re

necessarily fuzzy.

Y4glory
  • 1,111
  • 6
  • 17
  • 2
    **great answer** except the last line about semantics, for accessibility semantics matter, adding unnecessary markup adds extra steps / announcements for screen reader users. – GrahamTheDev Apr 09 '20 at 07:16
  • 1
    I did not think about accessibility which I should do more often. Thanks for the insight! – Y4glory Apr 09 '20 at 07:26