<nav>

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

HTML <nav> 元素代表一個網頁中提供導航欄連結的區域,不管是當前網頁或者其他網頁,還是這個連結最終抵達的只是當前網頁的某個區塊,或者會抵達其他網頁,常見的導航欄範例有菜單、內容的表單,以及頁面本身。

Content categories 流內容sectioning content、palpable content.
允許內容 流內容
標籤省略 不允許,開始和結束標籤都是必須的。
Permitted parents Any element that accepts flow content.
Permitted ARIA roles None
DOM interface HTMLElement

屬性

此元素只有全域屬性

使用筆記

  • 不是所有的文件連結都需要在 <nav> 元素裡面,它僅適用於主要的導航鏈接塊。一般來說 <footer> 元素常常有一個不需要在 <nav> 元素裡面的的鏈接列表。
  • 文件可以有很多個 <nav> 元素。例如說,一個用做網站導覽、另一個用做頁內導覽。
  • 面向身障用戶的螢幕閱讀器的用戶代理(User agent),可以決定要不要在初始渲染時省略這個元素的內容。

範例

在這個範例,<nav> 區塊用於包含連結的無序清單 (<ul>)。透過合適的 CSS,它能夠顯示為 sidebar、導覽列、以及下拉式選單。

html
<nav class="menu">
  <ul>
    <li><a href="#">Home</a></li>
    <li><a href="#">About</a></li>
    <li><a href="#">Contact</a></li>
  </ul>
</nav>

規範

Specification
HTML
# the-nav-element

瀏覽器相容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
nav

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

參見