# Header and menu

> The header appears at the top of every page, with your logo and a navigation menu that collapses into a toggle on small screens.

Source: https://www.zenplates.co/documentation/elements/header-and-menu/ (Elements › Navigation)

The header is rendered by the `header.hbs` template and most of its appearance is controlled by the **Header elements** theme settings, so you won't usually need to change its markup.

## Usage

The `.header` element uses the theme's `header` [Alpine.js](https://alpinejs.dev/) component (`x-data="header"`), which opens and closes the menu and keeps track of whether the header is fixed or stuck to the top of the page. Inside a [container](https://www.zenplates.co/documentation/elements/containers), it contains:

- A `.logo-link` link containing the `.logo` image and an optional `.tagline`.
- A `.menu-toggle` button, with `x-bind="trigger"`, which opens the menu on small screens. It's hidden from the **Mobile menu breakpoint** up.
- A `.backdrop` that covers the page while the menu is open on small screens.
- A `<nav class="nav menu">` element, with `x-bind="menu"`, that contains the header's links, search and dropdowns as `.nav-link` elements.

**Example: Header**

```html
<header class="header" x-data="header">
  <div class="container flex align-items-center justify-content-between h-full">
    <a class="logo-link nav-link flex align-items-center px-0 mr-auto z-100" href="{{page_path 'help_center'}}">
      <img class="logo block img-fluid" src="{{settings.logo}}" alt="{{t 'home_page' name=help_center.name}}">
    </a>
    <button class="menu-toggle nav-link ml-2 md:hidden" aria-label="{{t 'toggle_navigation'}}" x-bind="trigger">
      <span></span>
    </button>
    <template x-teleport=".header" @click="close">
      <div class="backdrop md:hidden" x-show="isMenuOpen" x-transition.opacity></div>
    </template>
    <nav class="nav menu transition md:p-0" x-cloak x-bind="menu">
      <a class="nav-link" href="...">Back to website</a>
      ...
    </nav>
  </div>
</header>
```

Make your browser window narrower than the medium breakpoint to see the menu toggle.

The component adds classes to the menu based on the theme settings: `.menu-{style}` for the mobile menu style, `.menu-{layout}` for the header layout and `.{breakpoint}:menu-expanded` to display the menu as a row of links from the mobile menu breakpoint up. In the theme's templates the `md:` prefixes above are set by the **Mobile menu breakpoint** setting.

## Menu styles

The **Mobile menu style** setting controls how the menu opens on small screens:

| Option       | Description                                                                         |
| ------------ | ----------------------------------------------------------------------------------- |
| **Standard** | The menu fades in below the header.                                                 |
| **Slide in** | The menu slides in from the left of the screen, with a copy of the logo at the top. |
| **Zoom in**  | The menu zooms in as a card over the page.                                          |

Set **Mobile menu breakpoint** to **None** to always show the menu toggle, at every screen size.

## Header settings

| Name                                           | Description                                                                                                                                                                                   |
| ---------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Header layout**                              | Positions the menu's links on the left, in the center or on the right of the header.                                                                                                          |
| **Full-width header**                          | Uses a full-width container so the header spans the whole page.                                                                                                                               |
| **Header height**                              | Sets the header height through `--height-header`.                                                                                                                                             |
| **Fixed header**                               | Places the header over the top of the hero section, using the **Header link color (fixed)** setting for its links until the header becomes stuck.                                             |
| **Sticky header**                              | Keeps the header at the top of the screen as visitors scroll: **Never**, **Always** or only when scrolling back up (**On scroll up**). A stuck header has the `.is-stuck` class and a shadow. |
| **Header link color**                          | The color of the header's links.                                                                                                                                                              |
| **Header background color**                    | The background color of the header.                                                                                                                                                           |
| **Header link 1–3 text/URL**                   | Up to three custom links.                                                                                                                                                                     |
| **Header search style**                        | Adds a search field to the header (**Inline**) or a button that opens one (**Button**).                                                                                                       |
| **Category list style**                        | Adds a **Categories** dropdown to the menu.                                                                                                                                                   |
| **Submit a Request link** and **Sign In link** | Shows these links as plain links or as buttons, or hides them.                                                                                                                                |

The language selector can also be shown in the header using the **Language selector location** setting in the **Translations** group.

To add or restyle header elements without code, use the [visual builder](https://www.zenplates.co/documentation/visual-builder/editing-global-elements).
