> ## Documentation Index
> Fetch the complete documentation index at: https://buttercms.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Navigation menu

> Use ButterCMS Collections to create a dynamic, multi-level menu your content team can edit in seconds.

ButterCMS Collections are a great fit to store navigation menu data, as they're both flexible and restricted to simple data types.

With a ButterCMS Collection, you can also:

* add logos and images
* enforce validation for strings, numbers, and URLs
* nest multiple levels of navigation

<Tip>
  For a full breakdown of ButterCMS Collections, [check out our core concepts](../../../core-concepts/content-types/collections) article.
</Tip>

## Modeling your menu in ButterCMS

### Create a single level menu

Follow the below steps to create a simple, flat menu with the following hierarchy:

<Card>
  <Tree>
    <Tree.Folder name="Main menu" defaultOpen>
      <Tree.File name="Home" />

      <Tree.File name="About" />

      <Tree.File name="Features" />

      <Tree.File name="Try it" />

      <Tree.File name="Testimonials" />

      <Tree.File name="Blog" />
    </Tree.Folder>
  </Tree>
</Card>

<Steps>
  <Step title="Create the Menu Item Collection">
    First, build the schema for your menu items. Important fields include:

    * **Label** - The display text
    * **URL** - What the item links to

    ![Navigation Menu Item collection schema](https://cdn.buttercms.com/Es7wKIpRSpiybCgYyDyo)

    Save it as **"Navigation Menu Item"**:

    ![Save as Navigation Menu Item](https://cdn.buttercms.com/mR0J72EYTBS7cA70UNEB)
  </Step>

  <Step title="Create the Parent Menu Collection">
    <Tip>
      Need more features than Collections allow? You can also use a Page to hold the Reference fields for your menu items.
    </Tip>

    Create a second Collection for the main menu that references the menu items:

    * **Name** - The navigation menu name
    * **Menu Items** - A Reference field linking to Navigation Menu Item (One-to-Many)

    ![Navigation Menu with reference field](https://cdn.buttercms.com/G4IRMnWSjyu7XqW0aoJd)
  </Step>

  <Step title="Add Menu Items">
    Click **New item** to add items to your Collection:

    ![Add new item button](https://cdn.buttercms.com/bP7QlsUMRKKMb05nG43n)

    Add each navigation item with its label and URL:

    ![Navigation Menu Item entry](https://cdn.buttercms.com/JvQdb2hGTYdUsQnpFwAc)
  </Step>

  <Step title="Link Items to the Menu">
    In your main Navigation Menu, click **Add Reference** and select all the items you want:

    ![Linking menu items via reference](https://cdn.buttercms.com/enpZyyaySOeyN9U3KscD)
  </Step>
</Steps>

### Building a complex multi-level menu

For complex menus with multiple levels, create separate Collections for each level.

Here's an example hierarchy:

![Complex multi-level navigation menu](https://cdn.buttercms.com/j0DnNVIbT6SvcBwu9sh4)

<Steps>
  <Step title="Create third-level collection">
    Start with the lowest-level children. Create **"Menu - Third Level"**:

    ![Third level menu item schema](https://cdn.buttercms.com/XGFo1IsDQ5aEJJXnpWjW)

    ![Save as Menu Third Level](https://cdn.buttercms.com/7Co6BaFwQCycNpzR1eIs)
  </Step>

  <Step title="Create second-level collection">
    **"Menu - Second Level"** includes a Reference field linking to Third Level:

    ![Second level with reference to third](https://cdn.buttercms.com/OxqgReWWTpmDY7ZwLzGo)
  </Step>

  <Step title="Create first-level collection">
    **"Menu - First Level"** references Second Level:

    ![First level with reference to second](https://cdn.buttercms.com/TSXo5kaGRQmto3w4ywtm)
  </Step>

  <Step title="Populate the collections">
    Add items to each level:

    **Third Level:**

    ![Third level menu items](https://cdn.buttercms.com/uazVjgBgTBu5aVGr8ZA8)

    **Second Level:**

    ![Second level menu items](https://cdn.buttercms.com/Kobvc8EZQQ2tY3OcPMbK)

    **First Level:**

    ![First level menu items](https://cdn.buttercms.com/6GFFJ9TSSCiusXZbEvWK)
  </Step>

  <Step title="Link collections together">
    Use the **Add Reference** button to connect items from one Collection to another:

    ![Linking collections via reference](https://cdn.buttercms.com/fhsbou6MTl2a1NnVn0z5)
  </Step>
</Steps>

## Common navigation patterns

<Tabs>
  <Tab title="Header with logo and links">
    Collection schema for **Header Navigation**:

    | Field             | Type       | Purpose                        |
    | ----------------- | ---------- | ------------------------------ |
    | `logo`            | Media      | Site logo image                |
    | `logo_alt`        | Short Text | Alt text for logo              |
    | `menu_items`      | Reference  | Links to Navigation Menu Items |
    | `cta_button_text` | Short Text | Call-to-action text            |
    | `cta_button_url`  | Short Text | CTA destination URL            |
  </Tab>

  <Tab title="Footer navigation">
    Collection schema for **Footer**:

    | Field            | Type       | Purpose                     |
    | ---------------- | ---------- | --------------------------- |
    | `company_name`   | Short Text | Business name               |
    | `tagline`        | Long Text  | Footer description          |
    | `column_1_title` | Short Text | First column heading        |
    | `column_1_links` | Reference  | Links for column 1          |
    | `column_2_title` | Short Text | Second column heading       |
    | `column_2_links` | Reference  | Links for column 2          |
    | `social_links`   | Repeater   | Social media icons and URLs |
    | `copyright_text` | Short Text | Copyright notice            |
  </Tab>

  <Tab title="E-commerce">
    For e-commerce or content-rich sites:

    | Field            | Type       | Purpose                  |
    | ---------------- | ---------- | ------------------------ |
    | `category_name`  | Short Text | Category title           |
    | `category_image` | Media      | Featured image           |
    | `featured_item`  | Reference  | Highlighted product/page |
    | `links`          | Reference  | Sub-items                |
    | `promo_banner`   | Media      | Promotional image        |
    | `promo_url`      | Short Text | Promo destination        |
  </Tab>
</Tabs>

## Fetching navigation via API

### JavaScript/Node.js

```javascript theme={null}
const Butter = require('buttercms');
const butter = Butter('your-api-token');

// Fetch navigation menu
const getNavigation = async () => {
  const response = await butter.content.retrieve(['navigation_menu'], {
    'fields.name': 'Main Menu'
  });

  return response.data.data.navigation_menu[0];
};

// Example response structure
{
  "name": "Main Menu",
  "menu_items": [
    { "label": "Home", "url": "/" },
    { "label": "About", "url": "/about" },
    { "label": "Features", "url": "/features" }
  ]
}
```

### Multi-level menu fetch

```javascript theme={null}
const getComplexNavigation = async () => {
  // Fetch all levels with nested references
  const response = await butter.content.retrieve([
    'menu_first_level'
  ], {
    levels: 3 // Fetch nested references up to 3 levels deep
  });

  return response.data.data.menu_first_level;
};
```

### React component

```jsx theme={null}
import { useEffect, useState } from 'react';
import Butter from 'buttercms';

const butter = Butter('your-api-token');

const Navigation = () => {
  const [menu, setMenu] = useState(null);

  useEffect(() => {
    const loadMenu = async () => {
      const response = await butter.content.retrieve(['navigation_menu'], {
        'fields.name': 'Main Menu'
      });
      setMenu(response.data.data.navigation_menu[0]);
    };

    loadMenu();
  }, []);

  if (!menu) return null;

  return (
    <nav>
      <ul>
        {menu.menu_items.map(item => (
          <li key={item.url}>
            <a href={item.url}>{item.label}</a>
          </li>
        ))}
      </ul>
    </nav>
  );
};

export default Navigation;
```

## Performance tips

<Tip>
  For global API calls like header and footer navigation, cache the response. A cache duration of 5-10 minutes is typical, or use on-demand revalidation when content changes via webhooks.
</Tip>

1. Cache navigation responses at the edge or in your app layer (5-10 minutes is typical).
2. Use `levels` sparingly to avoid oversized responses for deep menus.

{/* /SOURCE */}

{/* /SOURCE */}

## Best practices

**Content modeling**

1. **Separate concerns**: Use different Collections for header vs footer
2. **Include icons**: Add optional Media fields for menu item icons
3. **Support external links**: Include a checkbox for "Open in new tab"
4. **Add ordering**: Use a Number field if you need custom sort order

**Accessibility**

1. **Use semantic HTML**: `<nav>`, `<ul>`, `<li>` elements
2. **Add ARIA labels**: `aria-label`, `aria-expanded` for dropdowns
3. **Keyboard navigation**: Ensure all items are focusable
4. **Mobile considerations**: Include hamburger menu for small screens
