HUGO

  • News
  • Docs
  • Themes
  • Showcase
  • Community
  • GitHub
Star

What's on this Page

  • What is a Menu in Hugo?
  • Add content to menus
  • Add Non-content Entries to a Menu
  • Nesting
  • Params
  • Render Menus
CONTENT MANAGEMENT

Menus

Hugo has a simple yet powerful menu system.

If all you want is a simple menu for your sections, see the “Section Menu for Lazy Bloggers” in Menu Templates.

You can do this:

  • Place content in one or many menus
  • Handle nested menus with unlimited depth
  • Create menu entries without being attached to any content
  • Distinguish active element (and active branch)

What is a Menu in Hugo?

A menu is a named array of menu entries accessible by name via the .Site.Menus site variable. For example, you can access your site’s main menu via .Site.Menus.main.

If you make use of the multilingual feature, you can define language-independent menus.

See the Menu Entry Properties for all the variables and functions related to a menu entry.

Add content to menus

Hugo allows you to add content to a menu via the content’s front matter.

Simple

If all you need to do is add an entry to a menu, the simple form works well.

A Single Menu

     
menu: main
menu = 'main'
{
   "menu": "main"
}

Multiple Menus

     
menu:
- main
- footer
menu = ['main', 'footer']
{
   "menu": [
      "main",
      "footer"
   ]
}

Advanced

     
menu:
  docs:
    parent: extras
    weight: 20
[menu]
  [menu.docs]
    parent = 'extras'
    weight = 20
{
   "menu": {
      "docs": {
         "parent": "extras",
         "weight": 20
      }
   }
}

Add Non-content Entries to a Menu

You can also add entries to menus that aren’t attached to a piece of content. This takes place in your Hugo project’s config file.

Here’s an example snippet pulled from a configuration file:

config.
     
menu:
  main:
  - identifier: about
    name: about hugo
    pre: <i class='fa fa-heart'></i>
    url: /about/
    weight: -110
  - name: getting started
    post: <span class='alert'>New!</span>
    pre: <i class='fa fa-road'></i>
    url: /getting-started/
    weight: -100
[menu]
[[menu.main]]
  identifier = 'about'
  name = 'about hugo'
  pre = "<i class='fa fa-heart'></i>"
  url = '/about/'
  weight = -110
[[menu.main]]
  name = 'getting started'
  post = "<span class='alert'>New!</span>"
  pre = "<i class='fa fa-road'></i>"
  url = '/getting-started/'
  weight = -100
{
   "menu": {
      "main": [
         {
            "identifier": "about",
            "name": "about hugo",
            "pre": "\u003ci class='fa fa-heart'\u003e\u003c/i\u003e",
            "url": "/about/",
            "weight": -110
         },
         {
            "name": "getting started",
            "post": "\u003cspan class='alert'\u003eNew!\u003c/span\u003e",
            "pre": "\u003ci class='fa fa-road'\u003e\u003c/i\u003e",
            "url": "/getting-started/",
            "weight": -100
         }
      ]
   }
}

The URLs must be relative to the context root. If the baseURL is https://example.com/mysite/, then the URLs in the menu must not include the context root mysite. Using an absolute URL will override the baseURL. If the value used for URL in the above example is https://subdomain.example.com/, the output will be https://subdomain.example.com.

Nesting

All nesting of content is done via the parent field.

The parent of an entry should be the identifier of another entry. The identifier should be unique (within a menu).

The following order is used to determine an Identifier:

.Name > .LinkTitle > .Title

This means that .Title will be used unless .LinkTitle is present, etc. In practice, .Name and .Identifier are only used to structure relationships and therefore never displayed.

In this example, the top level of the menu is defined in your site config file. All content entries are attached to one of these entries via the .Parent field.

Params

You can also add user-defined content to menu items via the params field.

A common use case is to define a custom param to add a css class to a specific menu item.

config.
     
menu:
  main:
  - identifier: about
    name: about hugo
    params:
      class: highlight-menu-item
    pre: <i class='fa fa-heart'></i>
    url: /about/
    weight: -110
[menu]
[[menu.main]]
  identifier = 'about'
  name = 'about hugo'
  pre = "<i class='fa fa-heart'></i>"
  url = '/about/'
  weight = -110
  [menu.main.params]
    class = 'highlight-menu-item'
{
   "menu": {
      "main": [
         {
            "identifier": "about",
            "name": "about hugo",
            "params": {
               "class": "highlight-menu-item"
            },
            "pre": "\u003ci class='fa fa-heart'\u003e\u003c/i\u003e",
            "url": "/about/",
            "weight": -110
         }
      ]
   }
}

Render Menus

See Menu Templates for information on how to render your site menus within your templates.

See Also

  • Menu Entry Properties
  • .HasMenuCurrent
  • .IsMenuCurrent
  • Menu Templates
  • About Hugo
    • Overview
    • Hugo's Security Model
    • Hugo and GDPR
    • What is Hugo
    • Hugo Features
    • The Benefits of Static
    • License
  • Getting Started
    • Get Started Overview
    • Quick Start
    • Install Hugo
    • Basic Usage
    • Directory Structure
    • Configuration
    • External Learning Resources
  • Hugo Modules
    • Hugo Modules Overview
    • Configure Modules
    • Use Hugo Modules
    • Theme Components
  • Content Management
    • Content Management Overview
    • Organization
    • Page Bundles
    • Content Formats
    • Diagrams
    • Front Matter
    • Build Options
    • Page Resources
    • Image Processing
    • Shortcodes
    • Related Content
    • Sections
    • Content Types
    • Archetypes
    • Taxonomies
    • Summaries
    • Links and Cross References
    • URL Management
    • Menus
    • Static Files
    • Table of Contents
    • Comments
    • Multilingual
    • Syntax Highlighting
  • Templates
    • Templates Overview
    • Templating
    • Template Lookup Order
    • Custom Output Formats
    • Base Templates and Blocks
    • Render Hooks
    • List Templates
    • Homepage Template
    • Section Templates
    • Taxonomy Templates
    • Single Page Templates
    • Content View Templates
    • Data Templates
    • Partial Templates
    • Shortcode Templates
    • Local File Templates
    • 404 Page
    • Menu Templates
    • Pagination
    • RSS Templates
    • Sitemap Templates
    • Robots.txt
    • Internal Templates
    • Alternative Templating
    • Template Debugging
  • Functions
    • Functions Quick Reference
    • .AddDate
    • .Format
    • .Get
    • .GetPage
    • .HasMenuCurrent
    • .IsMenuCurrent
    • .Param
    • .Render
    • .RenderString
    • .Scratch
    • .Unix
    • absLangURL
    • absURL
    • after
    • anchorize
    • append
    • apply
    • base64
    • chomp
    • complement
    • cond
    • countrunes
    • countwords
    • default
    • delimit
    • dict
    • echoParam
    • emojify
    • eq
    • errorf and warnf
    • fileExists
    • findRE
    • first
    • float
    • ge
    • getenv
    • group
    • gt
    • hasPrefix
    • highlight
    • hmac
    • htmlEscape
    • htmlUnescape
    • hugo
    • humanize
    • i18n
    • Image Filters
    • in
    • index
    • int
    • intersect
    • isset
    • jsonify
    • lang
    • lang.Merge
    • last
    • le
    • len
    • lower
    • lt
    • markdownify
    • Math
    • md5
    • merge
    • ne
    • now
    • os.Stat
    • partialCached
    • path.Base
    • path.BaseName
    • path.Clean
    • path.Dir
    • path.Ext
    • path.Join
    • path.Split
    • plainify
    • pluralize
    • print
    • printf
    • println
    • querify
    • range
    • readDir
    • readFile
    • ref
    • reflect.IsMap
    • reflect.IsSlice
    • relLangURL
    • relref
    • relURL
    • replace
    • replaceRE
    • safeCSS
    • safeHTML
    • safeHTMLAttr
    • safeJS
    • safeURL
    • seq
    • sha
    • shuffle
    • singularize
    • site
    • slice
    • slicestr
    • sort
    • split
    • string
    • strings.Count
    • strings.HasSuffix
    • strings.Repeat
    • strings.RuneCount
    • strings.TrimLeft
    • strings.TrimPrefix
    • strings.TrimRight
    • strings.TrimSuffix
    • substr
    • symdiff
    • templates.Exists
    • time
    • time.Format
    • title
    • transform.Unmarshal
    • trim
    • truncate
    • union
    • uniq
    • upper
    • urlize
    • urls.Parse
    • where
    • with
  • Variables
    • Variables Overview
    • Site Variables
    • Page Variables
    • Shortcode Variables
    • Pages Methods
    • Taxonomy Variables
    • File Variables
    • Menu Entry Properties
    • Git Variables
    • Sitemap Variables
  • Hugo Pipes
    • Hugo Pipes Overview
    • Hugo Pipes
    • SASS / SCSS
    • PostProcess
    • PostCSS
    • JavaScript Building
    • Babel
    • Asset minification
    • Asset bundling
    • Fingerprinting and SRI
    • Resource from Template
    • Resource from String
  • CLI
  • Troubleshooting
    • Troubleshoot
    • FAQ
    • Build Performance
  • Tools
    • Developer Tools Overview
    • Migrations
    • Starter Kits
    • Frontends
    • Editor Plug-ins
    • Search
    • Other Projects
  • Hosting & Deployment
    • Hosting & Deployment Overview
    • Hugo Deploy
    • Host on AWS Amplify
    • Host on Netlify
    • Host on Render
    • Host on Firebase
    • Host on GitHub
    • Host on GitLab
    • Hosting on KeyCDN
    • Host on Cloudflare Pages
    • Deployment with Rsync
    • Deployment with Rclone
  • Contribute
    • Contribute to Hugo
    • Development
    • Documentation
    • Themes
  • Maintenance
Last updated: November 4, 2021: Add code toggle to menus page (#1568) (c3088c4fc)
Improve this page
By the Hugo Authors
Hugo Logo
  • File an Issue
  • Get Help
  • Discuss Source Code
  • @GoHugoIO
  • @spf13
  • @bepsays

Netlify badge

 
 

Hugo Sponsors

Logo for Linode
Logo for eSolia
Logo for Brave
 

The Hugo logos are copyright © Steve Francia 2013–2022.

The Hugo Gopher is based on an original work by Renée French.

  • News
  • Docs
  • Themes
  • Showcase
  • Community
  • GitHub
  • About Hugo
  • Getting Started
  • Hugo Modules
  • Content Management
  • Templates
  • Functions
  • Variables
  • Hugo Pipes
  • CLI
  • Troubleshooting
  • Tools
  • Hosting & Deployment
  • Contribute
  • Maintenance