Navbar

Materialize is a modern responsive CSS framework based on Material Design by Google.

Left Aligned Links

To left align your navbar links, just add a left class to your

<ul></ul> that contains them.



<nav>
  <div class="nav-wrapper">
    <a href="#" class="brand-logo right">Logo</a>
    <ul id="nav-mobile" class="left hide-on-med-and-down">
      <li><a href="sass.html">Sass</a></li>
      <li><a href="badges.html">Components</a></li>
      <li><a href="collapsible.html">JavaScript</a></li>
    </ul>
  </div>
</nav>

        

Centering the logo

The logo will center itself on medium and down screens, but if you want the logo to always be centered, add the center class to your

<a class="brand-logo"></a>. You will have to make sure yourself that links do not overlap if you use this.



<nav>
  <div class="nav-wrapper">
    <a href="#" class="brand-logo center">Logo</a>
    <ul id="nav-mobile" class="left hide-on-med-and-down">
      <li><a href="sass.html">Sass</a></li>
      <li><a href="badges.html">Components</a></li>
      <li><a href="collapsible.html">JavaScript</a></li>
    </ul>
  </div>
</nav>

        

Active Items

Add active class to your li tags to denote the current page.



<nav>
  <div class="nav-wrapper">
    <a href="#!" class="brand-logo center">Logo</a>
    <ul class="left hide-on-med-and-down">
      <li><a href="sass.html">Sass</a></li>
      <li><a href="badges.html">Components</a></li>
      <li class="active"><a href="collapsible.html">JavaScript</a></li>
    </ul>
  </div>
</nav>

        

Icon Links

You can add icons into links. For icon only links you don't need any additional class. Just pop the i tag in and it will work.



<nav>
  <div class="nav-wrapper">
    <a href="#!" class="brand-logo"><i class="material-icons">cloud</i>Logo</a>
    <ul class="right hide-on-med-and-down">
      <li><a href="sass.html"><i class="material-icons">search</i></a></li>
      <li><a href="badges.html"><i class="material-icons">view_module</i></a></li>
      <li><a href="collapsible.html"><i class="material-icons">refresh</i></a></li>
      <li><a href="mobile.html"><i class="material-icons">more_vert</i></a></li>
    </ul>
  </div>
</nav>

For adding an icon to a text link you need to add either a left or right class to the icon depending on where you want the icon to be.



<nav>
  <div class="nav-wrapper">
    <a href="#!" class="brand-logo">Logo</a>
    <ul class="right hide-on-med-and-down">
      <li><a href="sass.html"><i class="material-icons left">search</i>Link with Left Icon</a></li>
      <li><a href="badges.html"><i class="material-icons right">view_module</i>Link with Right Icon</a></li>
    </ul>
  </div>
</nav>

Buttons

You can add buttons into links. For buttons you don't need any additional class. Just pop the .btn class on the a tag.



<nav>
  <div class="nav-wrapper">
    <a href="#!" class="brand-logo">Logo</a>
    <ul class="right hide-on-med-and-down">
      <li><a class="waves-effect waves-light btn">Button</a></li>
      <li><a class="waves-effect waves-light btn">Button <i class="material-icons right">cloud</i></a></li>
      <li><a class="waves-effect waves-light btn-large">Large Button</a></li>
    </ul>
  </div>
</nav>

Halfway FAB in Extended Navbar

Add a halfway FAB to your extended navbar.



<nav class="nav-extended">
  <div class="nav-wrapper">
    <a href="#!" class="brand-logo">Logo</a>
    <ul class="right hide-on-med-and-down">
      <li><a>A link</a></li>
      <li><a>A second link</a></li>
      <li><a>A third link</a></li>
    </ul>
  </div>
  <div class="nav-content">
    <span class="nav-title">Title</span>
    <a class="btn-floating btn-large halfway-fab waves-effect waves-light">
      <i class="material-icons">add</i>
    </a>
  </div>
</nav>

Search Bar

You can add a search form in the navbar.



<nav>
  <div class="nav-wrapper">
    <form>
      <div class="input-field">
        <input id="search" type="search" required>
        <label class="label-icon" for="search"><i class="material-icons">search</i></label>
        <i class="material-icons">close</i>
      </div>
    </form>
  </div>
</nav>

Mobile Collapse Button

When your nav bar is resized, you will see that the links on the right turn into a hamburger icon menu. Take a look at the example below to get this functionality. Add the entire sidenav-trigger line to your nav.



<nav>
  <div class="nav-wrapper">
    <a href="#!" class="brand-logo">Logo</a>
    <a href="#" data-target="mobile-demo" class="sidenav-trigger"><i class="material-icons">menu</i></a>
    <ul class="right hide-on-med-and-down">
      <li><a href="sass.html">Sass</a></li>
      <li><a href="badges.html">Components</a></li>
      <li><a href="collapsible.html">Javascript</a></li>
      <li><a href="mobile.html">Mobile</a></li>
    </ul>
  </div>
</nav>

<ul class="sidenav" id="mobile-demo">
  <li><a href="sass.html">Sass</a></li>
  <li><a href="badges.html">Components</a></li>
  <li><a href="collapsible.html">Javascript</a></li>
  <li><a href="mobile.html">Mobile</a></li>
</ul>

          
Initialization

After including the sidenav-trigger line into your navbar, all you have to do now initialize the plugin. This example below assumes you have not modified the classes in the above example. In the case that you have, just change the selector in the line below to match it.


  document.addEventListener('DOMContentLoaded', function() {
    var elems = document.querySelectorAll('.sidenav');
    var instances = M.Sidenav.init(elems, options);
  });