<nav>: Das Navigationselement
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.
Das <nav>
HTML Element repräsentiert einen Abschnitt einer Seite, dessen Zweck es ist, Navigationslinks bereitzustellen, entweder innerhalb des aktuellen Dokuments oder zu anderen Dokumenten. Typische Beispiele für Navigationsabschnitte sind Menüs, Inhaltsverzeichnisse und Indizes.
Probieren Sie es aus
<nav class="crumbs">
<ol>
<li class="crumb"><a href="#">Bikes</a></li>
<li class="crumb"><a href="#">BMX</a></li>
<li class="crumb">Jump Bike 3000</li>
</ol>
</nav>
<h1>Jump Bike 3000</h1>
<p>
This BMX bike is a solid step into the pro world. It looks as legit as it
rides and is built to polish your skills.
</p>
nav {
border-bottom: 1px solid black;
}
.crumbs ol {
list-style-type: none;
padding-left: 0;
}
.crumb {
display: inline-block;
}
.crumb a::after {
display: inline-block;
color: #000;
content: ">";
font-size: 80%;
font-weight: bold;
padding: 0 3px;
}
Attribute
Dieses Element enthält nur die globalen Attribute.
Nutzungshinweise
- Es ist nicht notwendig, dass alle Links in einem
<nav>
Element enthalten sind.<nav>
ist nur für einen bedeutenden Block von Navigationslinks gedacht; typischerweise enthält das<footer>
Element oft eine Liste von Links, die nicht in einem<nav>
Element sein müssen. - Ein Dokument kann mehrere
<nav>
Elemente haben, zum Beispiel eines für die Seitennavigation und eines für die interne Navigation auf der Seite.aria-labelledby
kann in einem solchen Fall verwendet werden, um die Barrierefreiheit zu fördern, siehe Beispiel. - Benutzeragenten, wie z.B. Bildschirmlesegeräte, die auf beeinträchtigte Benutzer abzielen, können dieses Element verwenden, um zu bestimmen, ob die anfängliche Darstellung von nur-Navigationsinhalten weggelassen werden soll.
Beispiele
In diesem Beispiel wird ein <nav>
Block verwendet, um eine ungeordnete Liste (<ul>
) von Links zu enthalten. Mit entsprechender CSS kann dies als Seitenleiste, Navigationsleiste oder Dropdown-Menü dargestellt werden.
<nav class="menu">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
Die Semantik des nav
Elements besteht darin, Links bereitzustellen. Ein nav
Element muss jedoch keine Liste enthalten, es kann auch andere Arten von Inhalten umfassen. In diesem Navigationsblock werden Links im Fließtext bereitgestellt:
<nav>
<h2>Navigation</h2>
<p>
You are on my home page. To the north lies <a href="/blog">my blog</a>, from
whence the sounds of battle can be heard. To the east you can see a large
mountain, upon which many <a href="/school">school papers</a> are littered.
Far up this mountain you can spy a little figure who appears to be me,
desperately scribbling a <a href="/school/thesis">thesis</a>.
</p>
<p>
To the west are several exits. One fun-looking exit is labeled
<a href="https://games.example.com/">"games"</a>. Another more
boring-looking exit is labeled <a href="https://isp.example.net/">ISP™</a>.
</p>
<p>
To the south lies a dark and dank <a href="/about">contacts page</a>.
Cobwebs cover its disused entrance, and at one point you see a rat run
quickly out of the page.
</p>
</nav>
Technische Zusammenfassung
Inhaltskategorien | Flussinhalt, Abschnitteinhalt, fühlbarer Inhalt. |
---|---|
Erlaubter Inhalt | Flussinhalt. |
Tag-Auslassung | Keine, sowohl das Anfangs- als auch das Endtag sind obligatorisch. |
Erlaubte Eltern | Jedes Element, das Flussinhalt akzeptiert. |
Implizite ARIA-Rolle |
navigation
|
Erlaubte ARIA-Rollen | Keine role erlaubt |
DOM-Schnittstelle | [`HTMLElement`](/de/docs/Web/API/HTMLElement) |
Spezifikationen
Specification |
---|
HTML # the-nav-element |