<ul>: 無序列表元素

基線 廣泛可用

此功能已經成熟,並在許多裝置和瀏覽器版本中正常執行。它從 2015 年 7 月.

<ul> HTML 元素表示一個無序專案列表,通常呈現為帶專案符號的列表。

嘗試一下

屬性

此元素包含 全域性屬性

compact 已棄用

此布林屬性暗示列表應以緊湊樣式呈現。此屬性的解釋取決於 使用者代理,並且並非在所有瀏覽器中都有效。

警告: 不要使用此屬性,因為它已棄用:請改用 CSS。要實現與 compact 屬性類似的效果,可以使用 line-height CSS 屬性,其值為 80%

type 已棄用

此屬性設定列表的專案符號樣式。在 HTML3.2 和 HTML 4.0/4.01 過渡版本中定義的值為

  • circle
  • disc
  • square

在 WebTV 介面中定義了第四種專案符號型別,但並非所有瀏覽器都支援它:triangle

如果不存在,並且沒有 CSS list-style-type 屬性應用於元素,則使用者代理會根據列表的巢狀級別選擇專案符號型別。

警告: 不要使用此屬性,因為它已棄用;請改用 CSS list-style-type 屬性。

使用說明

  • <ul> 元素用於對沒有數字順序的一組專案進行分組,它們在列表中的順序無關緊要。通常,無序列表專案以專案符號顯示,專案符號可以有多種形式,例如點、圓圈或正方形。專案符號樣式不在頁面的 HTML 描述中定義,而是在其關聯的 CSS 中定義,使用 list-style-type 屬性。
  • <ul><ol> 元素可以根據需要進行巢狀。此外,巢狀列表可以在 <ol><ul> 之間交替使用,沒有限制。
  • <ol><ul> 元素都代表一個專案列表。它們的區別在於,對於 <ol> 元素,順序是有意義的。要確定使用哪一個,嘗試更改列表項的順序;如果含義發生改變,則應使用 <ol> 元素,否則可以使用 <ul>

示例

簡單示例

html
<ul>
  <li>first item</li>
  <li>second item</li>
  <li>third item</li>
</ul>

結果

巢狀列表

html
<ul>
  <li>first item</li>
  <li>
    second item
    <!-- Look, the closing </li> tag is not placed here! -->
    <ul>
      <li>second item first subitem</li>
      <li>
        second item second subitem
        <!-- Same for the second nested unordered list! -->
        <ul>
          <li>second item second subitem first sub-subitem</li>
          <li>second item second subitem second sub-subitem</li>
          <li>second item second subitem third sub-subitem</li>
        </ul>
      </li>
      <!-- Closing </li> tag for the li that
                  contains the third unordered list -->
      <li>second item third subitem</li>
    </ul>
    <!-- Here is the closing </li> tag -->
  </li>
  <li>third item</li>
</ul>

結果

無序列表中的有序列表

html
<ul>
  <li>first item</li>
  <li>
    second item
    <!-- Look, the closing </li> tag is not placed here! -->
    <ol>
      <li>second item first subitem</li>
      <li>second item second subitem</li>
      <li>second item third subitem</li>
    </ol>
    <!-- Here is the closing </li> tag -->
  </li>
  <li>third item</li>
</ul>

結果

技術摘要

內容類別 流內容,如果 <ul> 元素的子元素包含至少一個 <li> 元素,則為 可感知內容
允許的內容 零個或多個 <li><script><template> 元素。
標籤省略 沒有,開始標籤和結束標籤都是必需的。
允許的父元素 任何接受 流內容 的元素。
隱式 ARIA 角色 list
允許的 ARIA 角色 directorygrouplistboxmenumenubarnonepresentationradiogrouptablisttoolbartree
DOM 介面 HTMLUListElement

規範

規範
HTML 標準
# the-ul-element

瀏覽器相容性

BCD 表格僅在瀏覽器中載入

另請參閱

  • 其他與列表相關的 HTML 元素:<ol><li><menu>
  • 可能對 <ul> 元素進行樣式設定特別有用的 CSS 屬性