What Is the HTML for Navigation Menu in WordPress?
The exact HTML that wp_nav_menu() and the Navigation block print in WordPress 7.1, what each class and ARIA attribute means, and how to change it.

The HTML for a WordPress navigation menu is a list of links inside a navigation landmark: a <nav> (or a <div>) wrapping a <ul>, one <li> per menu item, an <a> inside each item, and a nested <ul> for every dropdown. Classic themes print it with wp_nav_menu(), which adds classes such as menu-item and current-menu-item. Block themes print it with the Navigation block, which wraps the same list in <nav class="wp-block-navigation"> and adds a menu button, a mobile overlay and ARIA attributes.
Our team rendered every code sample on this page on a clean WordPress 7.1.4 install with the Twenty Twenty-Five theme on 18 November 2026, and checked each filter and class name against the core source. Nothing below is guessed from an old tutorial.
This page has no recorded Search Console queries yet, so the headings follow the questions theme developers and site owners ask when they open the browser inspector and try to make sense of a WordPress menu.
What is the HTML for a navigation menu in WordPress?
At its simplest, it is this. Everything WordPress prints is a richer version of the same pattern:
<nav aria-label="Primary">
<ul>
<li><a href="/recipes/">Recipes</a></li>
<li>
<a href="/about/" aria-current="page">About</a>
<ul>
<li><a href="/about/team/">Team</a></li>
</ul>
</li>
<li><a href="/contact/">Contact</a></li>
</ul>
</nav>Three parts carry the meaning. The <nav> element tells browsers and screen readers that this block of links is site navigation. The list tells them how many items there are and how they nest. The aria-current="page" attribute marks the link for the page the visitor is on.
You never type this by hand in WordPress. You build the menu in the admin, and WordPress generates the markup. What changes between themes is who generates it: a PHP function in classic themes, a block in block themes.
What HTML does wp_nav_menu() print in a classic theme?
In a classic theme, the header template calls wp_nav_menu() and passes a theme location such as primary. WordPress finds the menu you assigned to that location under Appearance > Menus and runs each item through the Walker_Nav_Menu class, which writes the HTML.
Here is the exact output for a menu called “Main” with three top-level items and one child page, rendered while viewing the About page. The only change we made is the domain:
<nav class="menu-main-container" aria-label="Primary">
<ul id="menu-main" class="menu">
<li id="menu-item-11" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-11">
<a href="https://example.com/category/recipes/">Recipes</a>
</li>
<li id="menu-item-14" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-12 current_page_item menu-item-has-children menu-item-14">
<a href="https://example.com/about/" aria-current="page">About</a>
<ul class="sub-menu">
<li id="menu-item-15" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-15">
<a href="https://example.com/about/team/">Team</a>
</li>
</ul>
</li>
<li id="menu-item-16" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-16">
<a href="https://example.com/contact/">Contact</a>
</li>
</ul>
</nav>That output came from these arguments: 'container' => 'nav' and 'container_aria_label' => 'Primary'. Leave them out and you get the defaults from core, which are worth knowing because most older themes rely on them:
- The wrapper is a
<div>, not a<nav>. Thecontainerargument defaults todiv. Core only acceptsdivornavhere unless a plugin widens the list with thewp_nav_menu_container_allowedtagsfilter. - The wrapper class is built from the menu slug. A menu named “Main” gets
menu-main-container, and its list getsid="menu-main"andclass="menu". Rename the menu and those selectors change, which is a classic way to break a stylesheet. - The list wrapper is a template. The
items_wrapargument defaults to<ul id="%1$s" class="%2$s">%3$s</ul>, so you can swap the outer list markup without a custom walker. - No ARIA label is added unless you ask. The
container_aria_labelargument arrived in WordPress 5.5 and is empty by default.
One detail surprises people. If the same menu is printed twice on one page (a header and a footer, say), the second copy has no id on its list items and its list ID becomes menu-main-1. Core does this on purpose with a filter on nav_menu_item_id so the page never has duplicate IDs. Style menu items by class, not by ID.
What do the classic menu classes mean?
Every <li> carries classes that describe the item and where the visitor is. These are the ones you will use most, all confirmed in wp-includes/nav-menu-template.php:
Class | Added when | Typical use |
|---|---|---|
| Always | Base style for every item |
| Always (the menu item post ID) | Target one item, for example a “Sign up” button |
| Depending on what the item links to | Style custom links differently from pages |
| The object type behind the link | Finer targeting than the type class |
| The item has a submenu | Add a dropdown arrow |
| The link matches the current page | Highlight the active item |
| A direct child is the current page | Highlight the parent of the active item |
| Any descendant is the current page | Keep a whole branch highlighted |
| Older page-based equivalents, still printed | Legacy themes; prefer the hyphenated names |
| The item links to the front page | Swap the label for a house icon |
| The item links to the privacy policy page | Move it to the footer style |
| On the nested | Position and hide the dropdown |
You can also type your own classes per item. In Appearance > Menus, open Screen Options at the top right and tick “CSS Classes”. Each menu item then gets a field, and whatever you type is added to that item’s <li>.
What happens when no menu is assigned?
If a theme location has no menu, wp_nav_menu() calls its fallback, which is wp_page_menu() unless the theme set 'fallback_cb' => false. The fallback lists every published page, and its markup is different:
<div class="menu">
<ul>
<li class="page_item page-item-12 page_item_has_children">
<a href="https://example.com/about/">About</a>
<ul class="children">
<li class="page_item page-item-13"><a href="https://example.com/about/team/">Team</a></li>
</ul>
</li>
<li class="page_item page-item-2"><a href="https://example.com/sample-page/">Sample Page</a></li>
</ul>
</div>Notice children instead of sub-menu and page_item instead of menu-item. A theme styled only for the real menu classes will look broken here, which is why a site suddenly shows “all my pages in the header” after a theme switch. Assign a menu to the location and the normal markup returns.
What HTML does the Navigation block output?
Block themes, Twenty Twenty-Five included, put a Navigation block in the header template part. The block stores its links in a wp_navigation post and renders them on the server. The list inside is familiar, but the wrapper is much larger, because the block ships its own responsive menu button and overlay.
Below is the front-end output for the same menu, rendered by WordPress 7.1.4 with the default “Mobile” overlay setting. We shortened the long Interactivity API attributes (the data-wp-* ones) to keep it readable; the structure and every class are exact:
<nav class="is-responsive wp-block-navigation is-layout-flex wp-block-navigation-is-layout-flex" aria-label="Primary" data-wp-interactive="core/navigation">
<button aria-haspopup="dialog" aria-label="Open menu" class="wp-block-navigation__responsive-container-open">
<svg aria-hidden="true" focusable="false">...</svg>
</button>
<div class="wp-block-navigation__responsive-container" id="modal-1" tabindex="-1">
<div class="wp-block-navigation__responsive-close" tabindex="-1">
<div class="wp-block-navigation__responsive-dialog">
<button aria-label="Close menu" class="wp-block-navigation__responsive-container-close">
<svg aria-hidden="true" focusable="false">...</svg>
</button>
<div class="wp-block-navigation__responsive-container-content" id="modal-1-content">
<ul class="wp-block-navigation__container is-responsive wp-block-navigation" aria-label="Primary">
<li class="wp-block-navigation-item wp-block-navigation-link">
<a class="wp-block-navigation-item__content" href="/recipes/">
<span class="wp-block-navigation-item__label">Recipes</span>
</a>
</li>
<li class="wp-block-navigation-item has-child open-on-hover-click wp-block-navigation-submenu" tabindex="-1">
<a class="wp-block-navigation-item__content" href="/about/">
<span class="wp-block-navigation-item__label">About</span>
</a>
<button aria-label="About submenu" class="wp-block-navigation__submenu-icon wp-block-navigation-submenu__toggle" data-wp-bind--aria-expanded="state.isSubmenuOpen">
<svg aria-hidden="true" focusable="false">...</svg>
</button>
<ul class="wp-block-navigation__submenu-container wp-block-navigation-submenu">
<li class="wp-block-navigation-item wp-block-navigation-link">
<a class="wp-block-navigation-item__content" href="/about/team/">
<span class="wp-block-navigation-item__label">Team</span>
</a>
</li>
</ul>
</li>
<li class="wp-block-navigation-item wp-block-navigation-link">
<a class="wp-block-navigation-item__content" href="/contact/">
<span class="wp-block-navigation-item__label">Contact</span>
</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</nav>Read it from the outside in. The <nav> holds two things: the “Open menu” button that small screens see, and a container that becomes a full-screen dialog when that button is pressed. On wider screens the same container simply shows the list inline. The switch happens in the block’s own stylesheet at a fixed min-width: 600px breakpoint, and the open and close behaviour runs on the Interactivity API (the core/navigation store), not on a theme script.
Navigation block classes and ARIA, explained
Markup | What it is for |
|---|---|
| The block wrapper on the |
| Present when the overlay is set to “Mobile” or “Always”; absent with “Off” |
| The menu (hamburger) button, hidden from 600px up unless the overlay is “Always” |
| Tells assistive tech that the button opens a dialog |
| The overlay; gets |
| Every item, links and submenus alike |
| The |
| A |
| The item has a submenu, the block’s version of |
| How the submenu opens |
| The nested |
| Bound to the submenu toggle button, flips between true and false |
| Printed on the link for the current page, same as the classic walker |
WordPress 7.0 changed two things here that older tutorials will not mention. The old on/off “open submenus on click” setting became a three-way submenuVisibility setting (hover, click or always), and the mobile overlay can now be built from a template part, so its content is no longer limited to the menu links. Both changes are visible in wp-includes/blocks/navigation.php; blocks saved before 7.0 are read with their old setting.
If you want only the plain list, with no button and no overlay, set the block’s Overlay Menu option to “Off”. The is-responsive class, the buttons and the dialog container all disappear, and what remains is close to the classic markup with different class names.
Classic menu vs Navigation block: which markup do you get?
Classic theme (wp_nav_menu) | Block theme (Navigation block) | |
|---|---|---|
Where you edit it | Appearance > Menus or the Customizer | Site Editor > Navigation, or the block in the header |
Where it is stored |
| One |
Outer wrapper |
| Always |
Item classes |
|
|
Submenu list |
|
|
Mobile menu | Whatever the theme builds | Built in: button, overlay dialog, 600px breakpoint |
Current page |
|
|
Change markup with | Arguments, nav_menu filters, custom walker | Block settings, block styles, render_block filter |
A block theme can still use classic menus: the Navigation block offers to import them. The import copies your classic menu into a new wp_navigation post, so later edits under Appearance > Menus do not flow into the block. Edit the block’s menu after importing.
How do I change the menu HTML in a classic theme?
Work from the lightest tool to the heaviest. Most changes need only arguments or one filter, and you should put the code in a child theme or a small plugin, never in the parent theme. Each snippet below ran on our WordPress 7.1.4 test site (checked on 18 November 2026).
Start with the function arguments
This call gives you a labelled <nav>, a custom list class, two levels at most, and no page-list fallback:
<?php
// Print the menu assigned to the "primary" location inside a labelled <nav>.
wp_nav_menu(
array(
'theme_location' => 'primary',
'container' => 'nav',
'container_aria_label' => 'Primary',
'menu_class' => 'site-menu',
'depth' => 2,
'fallback_cb' => false,
)
);The full argument list is on the wp_nav_menu() reference page. The ones people miss are depth (stop runaway nesting), items_wrap (change the outer list) and item_spacing (set it to discard to remove whitespace between items, useful for inline-block layouts).
Then reach for the nav menu filters
Filters change the markup of a menu without replacing the walker. These three cover most real requests: a class on each item, attributes on each link, and a new class for submenus. Every callback checks the theme location so footer and mobile menus are left alone:
<?php
// Add a class to every <li> in the "primary" location only.
add_filter( 'nav_menu_css_class', function ( $classes, $menu_item, $args ) {
if ( isset( $args->theme_location ) && 'primary' === $args->theme_location ) {
$classes[] = 'site-menu__item';
}
return $classes;
}, 10, 3 );
// Add a class to every link, and open external links in a new tab safely.
add_filter( 'nav_menu_link_attributes', function ( $atts, $menu_item, $args ) {
if ( isset( $args->theme_location ) && 'primary' === $args->theme_location ) {
$atts['class'] = 'site-menu__link';
$home_host = wp_parse_url( home_url(), PHP_URL_HOST );
$link_host = isset( $atts['href'] ) ? wp_parse_url( $atts['href'], PHP_URL_HOST ) : null;
if ( $link_host && $link_host !== $home_host ) {
$atts['target'] = '_blank';
$atts['rel'] = 'noopener';
}
}
return $atts;
}, 10, 3 );
// Rename the sub-menu class from "sub-menu" to "site-menu__submenu".
add_filter( 'nav_menu_submenu_css_class', function ( $classes, $args ) {
if ( isset( $args->theme_location ) && 'primary' === $args->theme_location ) {
$classes = array( 'site-menu__submenu' );
}
return $classes;
}, 10, 2 );Here is the full set the walker offers, from class-walker-nav-menu.php and nav-menu-template.php:
Filter | Changes | Since |
|---|---|---|
| Classes on each | 3.0 |
| The | 3.0.1 |
| Any attribute on each | 6.3 |
| Attributes on each | 3.6 |
| The link text | 4.4 |
| Classes on each submenu | 4.8 |
| Any attribute on each submenu | 6.3 |
| The finished HTML of one item, before its children | 3.0 |
| The whole list of items as an HTML string | 3.0 |
| The sorted item objects, before any HTML exists | 3.1 |
| The arguments, before anything runs | 3.0 |
Two habits keep these safe. Return what you received when your condition does not match, and escape anything you add. nav_menu_link_attributes values are escaped by the walker, but wp_nav_menu_items and walker_nav_menu_start_el hand you raw HTML, so anything you append there must already be escaped.
Write a custom walker only for structural changes
A walker earns its place when you need different elements, not just different attributes: a <span> around every label, a button for each dropdown, or mega-menu columns. Extend Walker_Nav_Menu and override only the method you need. This one keeps all core behaviour and wraps each label:
<?php
// Wrap each link label in a <span> so it can be styled separately.
class TWP_Label_Walker extends Walker_Nav_Menu {
public function start_el( &$output, $data_object, $depth = 0, $args = null, $current_object_id = 0 ) {
$item_output = '';
parent::start_el( $item_output, $data_object, $depth, $args, $current_object_id );
$output .= preg_replace( '#(<a[^>]*>)(.*?)(</a>)#s', '$1<span class="site-menu__label">$2</span>$3', $item_output, 1 );
}
}
// Usage: wp_nav_menu( array( 'theme_location' => 'primary', 'walker' => new TWP_Label_Walker() ) );Since WordPress 6.7 the core walker no longer prints the redundant title attribute on links, so if an old custom walker copied that code, it is safe to drop.
How do I change the Navigation block’s markup?
The Navigation block is configured, not templated. Start in the editor: the block settings choose the overlay mode, submenu behaviour and whether the submenu arrow shows. The block uses the menu’s name as the aria-label on its <nav>, so renaming the menu in the Site Editor changes what screen readers announce, and core appends a number when two navigation blocks on one page share a name. Colours, typography and spacing go in Styles or in theme.json under styles.blocks["core/navigation"].
When settings are not enough, you have two code routes.
Add a block style for a new look
A block style adds a class such as is-style-pill-links that editors can pick in the sidebar. It changes no markup, so it survives every core update:
<?php
// Register a "Pill links" style variation for the Navigation block.
add_action( 'init', function () {
register_block_style(
'core/navigation',
array(
'name' => 'pill-links',
'label' => __( 'Pill links', 'your-textdomain' ),
'inline_style' => '.wp-block-navigation.is-style-pill-links .wp-block-navigation-item__content { padding: 0.4em 1em; border-radius: 999px; }',
)
);
} );Filter the rendered HTML for attribute changes
For a class or attribute the settings do not offer, filter the block’s output and edit it with WP_HTML_Tag_Processor, the HTML API that core itself uses. It is safer than regular expressions because it understands tags and attributes:
<?php
// Add a class to the Navigation block's <nav> wrapper on the front end.
add_filter( 'render_block_core/navigation', function ( $block_content, $block ) {
$tags = new WP_HTML_Tag_Processor( $block_content );
if ( $tags->next_tag( 'nav' ) ) {
$tags->add_class( 'site-nav' );
}
return $tags->get_updated_html();
}, 10, 2 );Keep these filters small. The block’s overlay depends on its exact class names and on the Interactivity API attributes, so removing or renaming those will break the mobile menu. Adding classes and data attributes is safe; restructuring is not. If you need truly different markup, a classic menu or a custom block is the cleaner path.
For grouping a Navigation block with a logo and a button in a header, the Group block is the usual container, and our guide to block patterns shows how to save a finished header for reuse.
Is the WordPress menu HTML accessible?
The core output is a good start, not a finished job. Both systems print a list of real links and add aria-current="page" to the current one. After that they differ.
- Landmark and label. The Navigation block always uses
<nav>and labels it with the menu name. A classic theme only does if it passes'container' => 'nav'. When a page has two navigation regions, each needs a distinctaria-labelsuch as “Primary” and “Footer” so screen reader users can tell them apart. - Dropdowns. The block adds a real
<button>for each submenu witharia-expanded, and handles Escape and focus leaving the menu. The classic walker prints no toggle at all; your theme must add one, or keyboard users may never reach the second level. - Mobile menu. The block’s overlay is a dialog with labelled open and close buttons. In a classic theme, the menu button is theme code, and the common mistake is a
<div>with a click handler instead of a<button>. - Hover only. A submenu that opens only on hover fails keyboard and touch users. The block’s “hover” mode still adds the toggle button for them; a classic theme needs
:focus-withinstyles or a script.
The W3C disclosure navigation example is the reference pattern both approaches follow. Test with the Tab key and a screen reader before you call a menu finished.
Does the menu markup affect SEO?
A little, and mostly through basics. Search engines read the links in your menu, so crawlable <a href> links matter more than any class name, and links that exist only in JavaScript are a risk. Both WordPress systems print real links in the server HTML, including the ones inside the mobile overlay, so you are covered by default.
The bigger factors are what you link to and how many links you add. A header with 80 links spreads attention thin for visitors and crawlers. The <nav> element itself is not a ranking factor, but it helps assistive technology and costs nothing.
Common mistakes people report
These problems come up again and again in the WordPress.org forums and the Gutenberg issue tracker. We paraphrase each one and link the source. Checked on 18 November 2026.
- “Appearance > Menus is gone.” A site owner on a block theme found only Themes and Editor under Appearance; the reply explained that block themes edit menus in the Site Editor instead. Core only shows the Menus screen when the theme supports menus or widgets. (WordPress.org support, around 2023)
- The header lists every page. When no menu is assigned to a location, or a menu has no visible items,
wp_nav_menu()falls back towp_page_menu()and prints all pages; a plugin author confirmed this in a thread about hidden items, and the fix is to assign a menu or set'fallback_cb' => false. (WordPress.org support thread) - The mobile breakpoint cannot be changed. The Navigation block collapses at a fixed 600px, which is too narrow for long menus on tablets. The request to make it configurable is still open, and newer duplicates keep being folded into it. (Gutenberg issue #45040, open since October 2022)
- Link spacing disappears in the mobile overlay. Padding set on navigation links shows on desktop but is ignored once the menu opens in the overlay, so the mobile list looks cramped. (Gutenberg issue #56140, open)
- A changed or imported menu does not update on the front end. Users switching the block to another menu, or importing a classic menu, saw the old links until they edited an item. That bug was fixed in 2023, but the related lesson stands: an imported classic menu is a copy, and duplicate imports with identical names still confuse people. (Gutenberg issue #51270, #39200)
Frequently asked questions
What HTML tag is used for a navigation menu?
The <nav> element wrapping a <ul> list of <li> items, each with an <a> link. WordPress follows this pattern in both classic and block themes.
How do I see the HTML of my WordPress menu?
Right-click a menu link on the front end and choose Inspect. The browser shows the generated markup, classes included. Viewing the page source works too, but the inspector also shows live changes such as is-menu-open.
Can I add a CSS class to one menu item without code?
Yes in a classic theme: enable “CSS Classes” in Screen Options on Appearance > Menus and type it into the item. In the Navigation block, select the link and add the class under Advanced > Additional CSS class(es).
Why does my menu have a div instead of a nav element?
Because wp_nav_menu() uses div as its default container. Pass 'container' => 'nav' and a container_aria_label, or filter wp_nav_menu_args if you cannot edit the theme template.
Can I use the Navigation block in a classic theme?
You can insert it in post content or a block-based widget area, but the header of a classic theme is PHP, so the theme decides. For a site-wide header menu in a classic theme, wp_nav_menu() is still the normal choice.
Where do I put menu customization code?
In a child theme’s functions.php or a small custom plugin, so a theme update does not erase it. If you are new to filters, our list of WordPress filters that replace plugins shows the pattern on everyday problems.
Related reading
Menus usually sit next to the site title and a call to action, so the header is where most of this markup ends up. If you are building a block theme home page, our guide on switching a pattern into your home page covers the template side. For the type side of the same header, see what the HTML for fonts looks like in WordPress.
Plugins we build and run
We maintain these ourselves, which is why we can support them on your site.
- BuddyNextThe self-hosted community engine for WordPress
- BuddyXFree community theme, Pro when you outgrow it
- ReignPremium community theme. Add pieces, build anything
- JetonomyCommunity forum and Q&A for WordPress
- EventonomyEvents and RSVPs for WordPress communities
- LearnomyCourses and learning communities on WordPress
- ListoraDirectories and listings your members can browse
- SnipShareCode sharing built for developer communities
- WB Ad ManagerAd placements that turn traffic into revenue
- WP Career BoardA job board your community actually uses
- WP Sell ServicesSell services with offers, orders, and payouts
- MediaVersePhotos, video, and media albums for members
- WB GamificationPoints, badges, and rewards that keep members active
- Product RoadmapPublic roadmaps with voting your users trust
Related Posts

LiteSpeed Cache Vulnerability CVE-2026-93389: Check Your Version and What Was Exposed

Freemius SDK Stored XSS: How to Find Every Bundled Copy on a Client Site (Anything Under 2.13.5)
