学习库HTMLLists and Tables

Lists and Tables

Represent sequences, groups, and truly tabular data with the right elements.

更新于 适用于 HTML Living Standard

Lists describe related items. Tables describe relationships across rows and columns. Using either for visual indentation or page layout throws that meaning away.

Choose the right list

Use ul when order does not matter, ol when it does, and dl for name-value pairs.

lists.html
<ol>
  <li>Create the HTML file.</li>
  <li>Add meaningful structure.</li>
  <li>Open it in a browser.</li>
</ol>

<dl>
  <dt>HTML</dt>
  <dd>Describes the content.</dd>
  <dt>CSS</dt>
  <dd>Controls the presentation.</dd>
</dl>

Lists may be nested when an item genuinely contains a sub-list. Keep the child list inside its parent li.

Mark up data tables

progress.html
<table>
  <caption>Course progress</caption>
  <thead>
    <tr><th scope="col">Course</th><th scope="col">Lessons</th></tr>
  </thead>
  <tbody>
    <tr><th scope="row">HTML</th><td>8</td></tr>
    <tr><th scope="row">CSS</th><td>10</td></tr>
  </tbody>
</table>

The caption names the table. Header cells and scope make the row-column relationship explicit.

Keep this

Use lists for groups or sequences and tables only when cells have meaningful row and column relationships.

学习位置已保存在此设备上。