清單相關標記包括 <OL>、<LI>、<UL>、<MENU>、<DIR>、<DL>、<DT>、<DD>。
<OL> 稱為順序清單標記,<LI> 則用來標示清單項目。所謂順序清單,就是每一項前面加上 1、2、3… 的編號,又稱編號清單。
<OL> 的參數(例如 <ol type="i" start="4"></ol>):
<LI> 的參數(例如 <li type="square" value="4">):
例子:
My best friends:
<ol>
<li>Michelle Wei
<li>Michael Wan
<li>Gloria Lam
</ol>
顯示結果:
My best friends:
<UL> 稱為無序清單標記。所謂無序清單就是每一項前面加上圓點或方塊等符號,故又稱符號清單。
參數(例如 <UL type="square">):type 設定符號款式,三種選擇同前,預設為 disc。
注意:由於 <UL> 與 <LI> 都有 type 參數,兩者盡量只選用其中一個,避免混淆。
例子:
My Homepages:
<ul>
<li>Penpals Garden
<li>ICQ Garden
<li>Software City
<li>Creation of Webpage
</ul>
顯示結果:
My Homepages:
這兩個標記都不為 W3C 所贊同,建議改用 <ul> 與 <ol>。它們基本上和 <ul> 一樣,在某些瀏覽器中會表現出 <ol> 的效果;舊版的 IE 或 Netscape 中,<DIR> 則不顯示符號或編號。用法與 <ul> 完全相同。
<dir>
<li>Penpals Garden
<li>ICQ Garden
<li>Software City
<li>Creation of Webpage
</dir>
顯示結果:
<DL> 稱為定義清單標記,<DT> 用來標示定義條目(術語),<DD> 用來標示定義內容。所謂定義清單是一種兩層的項目清單,不帶符號與編號。
三個標記都沒有常用參數。<DT> 與 <DD> 可以獨立使用,但部分舊瀏覽器(如 IE 3.0)並不支援。另外 <DD> 常被用來製造段落首行的縮排效果。
例子:
<dl>
<dt>How to use Definition List
<dd>First, you should not place paragraph tag right after or before a list structure or between the items of a list. In certain contexts, use of extra paragraph tags should always be avoided. When you realize this concept, it is quite easy to write a HTML.
<dt>Other things to know
<dd>We usually put only ONE Definition tag following the Definition Term tag; more than one DD tag is not recommended. Besides, unlike Definition List is a nonempty tag, both Definition Term and Definition Description are empty tags.
</dl>
顯示結果:
<MENU> 與 <DIR> 已在 HTML5 中被移除(<menu> 曾被重新定義為語意化的選單容器,但瀏覽器支援仍不一致)。<OL>、<UL>、<DL> 三者則是 HTML5 完整保留的語意標籤,值得放心使用。
實際開發中有兩個重點:一是清單的 type、start、value 屬性雖仍可用,但若要客製符號樣式(自訂圖示、顏色、編號格式),應改用 CSS 的 list-style-type、list-style-image 與 ::marker 偽元素;二是 <UL> 與 <LI> 雖然允許省略 </LI> 結束標籤,但養成關閉的習慣對後續維護與團隊協作都有明顯好處。
導覽列(navigation)在語意上正是「一組同類型的連結清單」,因此以 <nav> 包 <ul> 是公認的標準寫法。