How to Create a Responsive Navigation Menu with Icons using CSS

A navigation menu is an essential part of any website.

It helps users find what they are looking for and navigate the site with ease.

In this tutorial, we will walk you through the process of creating a responsive navigation menu with icons using CSS.

Responsive Design

Responsiveness is a must-have feature for any website in today’s world.

With an increasing number of users accessing websites on different devices, it’s crucial to ensure that your site is responsive and adapts to different screen sizes.

A responsive navigation menu should be able to adjust its layout and icons to match the device’s screen size.

HTML Structure

Before we dive into the CSS, let’s create the basic HTML structure for our navigation menu.

A navigation menu is usually a list of links, and we can create it using an unordered list.

<nav>
  <ul>
    <li><a href="#">Home</a></li>
    <li><a href="#">About</a></li>
    <li><a href="#">Services</a></li>
    <li><a href="#">Contact</a></li>
  </ul>
</nav>

CSS Styling

Next, we will add some basic styling to our navigation menu using CSS.

We will give it a fixed width and height and set the background color to gray.

nav {
  width: 100%;
  height: 50px;
  background-color: gray;
  display: flex;
  justify-content: center;
  align-items: center;
}

nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
}

nav li {
  flex: 1;
  text-align: center;
}

nav a {
  display: block;
  padding: 16px;
  color: white;
  text-decoration: none;
}

Icons

Now that our navigation menu is styled, it’s time to add icons.

We can use font icons like Font Awesome or SVG icons for this purpose.

To keep things simple, we will use Font Awesome icons in this example.

First, you need to include the Font Awesome CSS file in your HTML.

<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.14.0/css/all.css" integrity="sha384-HzLeBuhoNPvSl5KYnjx0BT+WB0QEEqLprO+NBkkk5gbc67FTaL7XIGa2w1L0Xbgc" crossorigin="anonymous">

Next, we will add icons to each link in our navigation menu.

<nav>
  <ul>
    <li><a href="#"><i class="fas fa-home"></i> Home</a></li>
    <li><a href="#"><i class="fas fa-info-circle"></i> About</a></li>
    <li><a href="#"><i class="fas fa-wrench"></i> Services</a></li>
    <li><a href="#"><i class="fas fa-envelope"></i> Contact</a></li>
  </ul>
</nav>

Responsiveness

Finally, we will make our navigation menu responsive. We will use media queries to adjust the layout of the menu for different screen sizes.

For small screens, we will stack the links vertically, and for larger screens, we will keep them horizontal.

@media (max-width: 768px) {
nav ul {
flex-direction: column;
}

nav li {
text-align: left;
width: 100%;
}
}

Conclusion

In this article, we have learned how to create a responsive navigation menu with icons using CSS.

With the HTML structure, CSS styling, and media queries, you can create a navigation menu that looks great on all devices.

With a few modifications, you can customize this menu to match your website’s style and requirements.

I hope this article was helpful and informative. If you have any questions or comments, please feel free to reach out.