HTML <nav> tagS2C Home   « HTML <nav> tag

Definition

The <nav> tag is used to define a navigational section for a HTML document.

Use the <nav> tag for grouping together major navigational sections of the page such as site navigation.

If supplying informational links such as sitemaps, contact information, terms of usage etc. then use the <footer> HTML tag instead.

The <nav> tag is a block element ie. it starts on a new line and covers the whole width of the page.

A document can have more than one <nav> tag.

The <nav> tag was introduced in HTML5.

Example


<header style="background-color:cyan">
  <h2>Some heading</h2>
  <p>Header content</p>
</header>
<nav style="background-color:lime">
  <ul>
    <li><a href="../../pages/aboutus.html">About Us</a></li>
    <li><a href="../../pages/linktous.html">Link To Us</a></li>
    <li><a href="mailto:charlie@htmldoctor.info">Contact Us</a></li>
  </ul>
</nav>
<main style="background-color:yellow">
  <h2>Main content heading</h2>
  <p>Main content</p>
</main>
<footer style="background-color:orange">
  <h2>Footer content heading</h2>
  <p>Footer content such as copyright, sitemaps, contact information</p>
</footer>

Some heading

Header content

Main content heading

Main content

Footer content heading

Footer content such as copyright, sitemaps, contact information

The following attributes can be used with the <nav> tag.


<nav> Specific Attributes
Attribute Value Description Example
There are no required or optional attributes specific to the <nav> tag.
<nav> Global Attributes
Attribute Description Example
Common
classSpecifies a classname for the element allowing you to apply the style of the predefined class to the content.

<nav class="name">Navigation links</nav>
idSpecifies a unique id for the element allowing you to apply the style of the predefined id to the content.

<nav id="name">Navigation links</nav>
styleSpecifies an inline style for the element allowing you to apply the style to the contentt.

<nav style="color:red;">Navigation links</nav>
titleSpecifies an inline style for the element allowing you to apply the style to the content.

<nav title="Content info">Navigation links</nav>
Keyboard
accesskeySpecifies a keyboard shortcut to associate with the element.

<nav accesskey="a">Navigation links</nav>
tabindexSpecifies a tab order for the element.

<nav tabindex="1">Navigation links</nav>
Language
dirSpecifies the directional flow of the content.

<!-- The text will flow from left to right -->
<nav dir="ltr">Navigation links</nav>
<!-- The text will flow from right to left -->
<nav dir="rtl">Navigation links</nav>
langSpecifies a language code for the content of the element.

<nav lang="en">Navigation links</nav>
spellcheckSpecifies an inline style for the element allowing you to apply the style to the contentt.

<!-- Valid values true and false. -->
<!-- Default inherited / browser specific. -->
<nav spellcheck="true">Navigation links</nav> 
translateSpecifies an inline style for the element allowing you to apply the style to the content.

<!-- Valid values yes and no. -->
<!-- Default yes. -->
<nav translate="no">Navigation links</nav> 
Miscellaneous
contenteditableSpecifies whether the content of the element is editable.

<!-- Valid values true and false. -->
<!-- Default inherited. -->
<nav contenteditable="true">Navigation links</nav> 
draggableSpecifies whether the element is draggable.

<!-- Valid values true and false. -->
<!-- Default browser specific. -->
<nav draggable="true">Navigation links</nav>
hiddenSpecifies whether the element is not yet, or no longer, relevant.

<!-- Valid values an empty string or hidden -->
<nav hidden>Navigation links</nav> 
<nav hidden="hidden">Navigation links</nav> 
<nav> Event Attributes
Attribute Description Example
Document Element
oncopyThe script to be run when the user copies the content of an element.

 <!-- Executes go() function -->
<nav oncopy="go()">Navigation links</nav> 
oncutThe script to be run when the user cuts the content of an element.

 <!-- Executes go() function -->
<nav oncut="go()">Navigation links</nav>
onpasteThe script to be run when the user pastes some content into an element.

 <!-- Executes go() function -->
<nav onpaste="go()">Navigation links</nav>
Drag and Drop
ondragThe script to be run when an element is dragged.

 <!-- Executes go() function -->
<nav ondrag="go()">Navigation links</nav>
ondragendThe script to be run when an element has stopped being dragged.

 <!-- Executes go() function -->
<nav ondragend="go()">Navigation links</nav>
ondragenterThe script to be run when an element has been dragged to a valid drop target.

 <!-- Executes go() function -->
<nav ondragenter="go()">Navigation links</nav>
ondragleaveThe script to be run when an element leaves a valid drop target.

 <!-- Executes go() function -->
<nav ondragleave="go()">Navigation links</nav>
ondragoverThe script to be run when an element is being dragged over a valid drop target.

 <!-- Executes go() function -->
<nav ondragover="go()">Navigation links</nav>
ondragstartThe script to be run at the start of a drag operation.

 <!-- Executes go() function -->
<nav ondragstart="go()">Navigation links</nav>
ondropThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<nav ondrop="go()">Navigation links</nav>
Form
onblurThe script to be run when the element loses focus.

 <!-- Executes go() function -->
<nav onblur="go()">Navigation links</nav>
onchangeThe script to be run when object changed and attempt to leave field.

 <!-- Executes go() function -->
<nav onchange="go()">Navigation links</nav>
oncontextmenuThe script to be run when a context menu is triggered.

 <!-- Executes go() function -->
<nav oncontextmenu="go()">Navigation links</nav>
onfocusThe script to be run when the element gets focus.

 <!-- Executes go() function -->
<nav onfocus="go()">Navigation links</nav>
oninputThe script to be run when an element gets user input.

 <!-- Executes go() function -->
<nav oninput="go()">Navigation links</nav>
oninvalidThe script to be run when an element is invalid.

 <!-- Executes go() function -->
<nav oninvalid="go()">Navigation links</nav>
onresetThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<nav onreset="go()">Navigation links</nav>
onselectThe script to be run when some or all of the contents of an object are selected.

 <!-- Executes go() function -->
<nav onselect="go()">Navigation links</nav>
onsubmitThe script to be run when a form is submitted.

 <!-- Executes go() function -->
<nav onsubmit="go()">Navigation links</nav>
Keyboard
onkeydownThe script to be run when an element is in focus and keyboard key is pressed down.

 <!-- Executes go() function -->
<nav onkeydown="go()">Navigation links</nav>
onkeypressThe script to be run when an element is in focus and keyboard key is pressed down and released.

 <!-- Executes go() function -->
<nav onkeypress="go()">Navigation links</nav>
onkeyupThe script to be run when an element is in focus and keyboard key is released.

 <!-- Executes go() function -->
<nav onkeyup="go()">Navigation links</nav>
Media
onabortThe script code to be run on abort.

 <!-- Executes go() function -->
<nav onabort="go()">Navigation links</nav>
oncanplayThe script to be run when a file has buffered enough so it is ready to start playing.

 <!-- Executes go() function -->
<nav oncanplay="go()">Navigation links</nav>
oncanplaythroughThe script to be run when a file can be played all the way to the end without further need of buffering.

 <!-- Executes go() function -->
<nav oncanplaythrough="go()">Navigation links</nav>
oncuechangeThe script to be run when the cue changes when using the track element.

 <!-- Executes go() function -->
<nav oncuechange="go()">Navigation links</nav>
ondurationchangeThe script to be run when the length of the media is changed.

 <!-- Executes go() function -->
<nav ondurationchange="go()">Navigation links</nav>
onemptiedThe script to be run when a media resource element suddenly becomes empty, usually due to an error.

 <!-- Executes go() function -->
<nav onemptied="go()">Navigation links</nav>
onendedThe script to be run when the media has reach the end.

 <!-- Executes go() function -->
<nav onended="go()">Navigation links</nav>
onloadeddataThe script to be run when media data is loaded and playback can start.

 <!-- Executes go() function -->
<nav onloadeddata="go()">Navigation links</nav>
onloadedmetadataThe script to be run when metadata has been loaded.

 <!-- Executes go() function -->
<nav onloadedmetadata="go()">Navigation links</nav>
onloadstartThe script to be run whenthe media resource has started loading.

 <!-- Executes go() function -->
<nav onloadstart="go()">Navigation links</nav>
onpauseThe script to be run when the media resource has been paused.

 <!-- Executes go() function -->
<nav onpause="go()">Navigation links</nav>
onplayThe script to be run when the media resource starts playback.

 <!-- Executes go() function -->
<nav onplay="go()">Navigation links</nav>
onplayingThe script to be run when when playback has already begun.

 <!-- Executes go() function -->
<nav onplaying="go()">Navigation links</nav>
onprogressThe script to be run when the browser is fetching the media data.

 <!-- Executes go() function -->
<nav onprogress="go()">Navigation links</nav>
onratechangeThe script to be run when the playback rate changes.

 <!-- Executes go() function -->
<nav onratechange="go()">Navigation links</nav>
onseekedThe script to be run when the seeking attribute is set to false indicating that seeking has finished.

 <!-- Executes go() function -->
<nav onseeked="go()">Navigation links</nav>
onseekingThe script to be run when the seeking attribute is set to true indicating that seeking is currently active.

 <!-- Executes go() function -->
<nav onseeking="go()">Navigation links</nav>
onstalledThe script to be run when the browser is unable to continue fetching media data.

 <!-- Executes go() function -->
<nav onstalled="go()">Navigation links</nav>
onsuspendThe script to be run when media data has stopped before being completely loaded.

 <!-- Executes go() function -->
<nav onsuspend="go()">Navigation links</nav>
ontimeupdateThe script to be run when the media resources current playback position has changed.

 <!-- Executes go() function -->
<nav ontimeupdate="go()">Navigation links</nav>
onvolumechangeThe script to be run when the volume has changed or been muted.

 <!-- Executes go() function -->
<nav onvolumechange="go()">Navigation links</nav>
onwaitingThe script to be run when the media resource has paused but is expected to resume.

 <!-- Executes go() function -->
<nav onwaiting="go()">Navigation links</nav>
Mouse
onclickThe script to be run when when a mouse is clicked on an element.

 <!-- Executes go() function -->
<nav onclick="go()">Navigation links</nav>
ondblclickThe script to be run when a mouse is double clicked on an element.

 <!-- Executes go() function -->
<nav ondblclick="go()">Navigation links</nav>
onmousedownThe script to be run when he mouse button is pressed down while the cursor is over an element.

 <!-- Executes go() function -->
<nav onmousedown="go()">Navigation links</nav>
onmousemoveThe script to be run when the mouse button is moved.

 <!-- Executes go() function -->
<nav onmousemove="go()">Navigation links</nav>
onmouseoutThe script to be run when the mouse cursor moves off an element.

 <!-- Executes go() function -->
<nav onmouseout="go()">Navigation links</nav>
onmouseoverThe script to be run when the mouse cursor moves over an element.

 <!-- Executes go() function -->
<nav onmouseover="go()">Navigation links</nav>
onmouseupThe script to be run when the mouse button is released while the cursor is over the element.

 <!-- Executes go() function -->
<nav onmouseup="go()">Navigation links</nav>
onwheelThe script to be run when the mouse wheel rolls up or down over an element.

 <!-- Executes go() function -->
<nav onwheel="go()">Navigation links</nav>
Scroll
onscrollThe script code to be run when the scrollbar of an element is being scrolled.

 <!-- Executes go() function -->
<nav onscroll="go()">Navigation links</nav> 
Window - NONE

Relevant HTML Tutorials

HTML Advanced - HTML Structure - Page