DEV Community

Cover image for How to Create an Engaging and Animated Menu Bar with HTML and CSS
Ayodeji Akintubi
Ayodeji Akintubi

Posted on

How to Create an Engaging and Animated Menu Bar with HTML and CSS

One of the surefire ways to enhance user experience on your website is by creating engaging and user-friendly navigation menus .

An animated menu bar not only makes navigation intuitive but also visually appealing.

You can create impressive and captivating animated menu bars that will keep users glued to your website.

In this tutorial, we will walk you through the step-by-step process of building a sleek and animated menu bar using HTML and key CSS concepts such as transitions.

We will cover key concepts like CSS transitions, transformations, and pseudo-classes to bring life to your navigation.

By the end of this tutorial, you'll have the knowledge and skills to design your animated menu bar that can elevate your website's overall look and feel.

So, let's dive into the world of web animations and create an eye-catching animated menu bar that will leave your visitors impressed!

HTML
In the HTML page, you lay the foundation for the menu. Here is where you will create the appropriate menu for your website.

For instance, if you intend to create a menu with the About Us, Home, and other necessary menus, you can write this code:


Menu Bar

        <ul>
            <li><a href="#" >Home</a></li>
            <li><a href="#"> About Us</a></li>
            <li><a href="#"> Services</a></li>
            <li><a href="#"> Blog</a></li>
            <li><a href="#"> Contact Us</a></li>
        </ul>
Enter fullscreen mode Exit fullscreen mode

In the above code, the code connects the HTML file with the CSS file to style the code.

Without the CSS code, here's the created menu bar:

Image description

The menu above is far from being intuitive, sleek, and visually appealing.

For the desired effect, let's style the menu via our CSS.

*CSS *

For easy connection, create a .css file and name it style.css or whatever catches your fancy. Note, though, that the css file name must correspond with the name in the html section.

Save this file in the same location or folder with your html file. Otherwise, the css and html files won't connect.

Then, add this code:

/The body section removes default borders and margins to allow you lay the menu as you desire/

body {
margin:0;
padding: 0;
box-sizing: border-box;
}

/This section removes the default bulleted listing/

   ul {
    list-style-type: none; 
     background-color: #333;
     overflow: hidden; 
        }
Enter fullscreen mode Exit fullscreen mode

/The float element aligns the menu to the right. You can change it to left if you wish to create a left-aligned menu/

   li {
    float: right; 
       }
Enter fullscreen mode Exit fullscreen mode

/Here is where you style each anchor. The text-decoration element removes the default menu underline./

   li a {
    display: block; 
    color: white; 
    text-align: center;
    padding: 14px 16px; 
    text-decoration: none;
   }
Enter fullscreen mode Exit fullscreen mode

/Here is where the real animation takes place. The transition-duration element changes the menu color within 3 seconds while the border-radius element changes the menu shape/

   li a:hover{
    background-color: yellow;
    transition-duration:  3s;
    width: 200px;
    border-radius: 75% 25%;
    color: black;
   }
Enter fullscreen mode Exit fullscreen mode

** Final Result
**

Each menu changes background color, shape, and text color when you hover over it.

Image description

Image description

Conclusion
You have effortlessly created an animated menu bar. Tweak the code and see what each line of code does or according to your preference.

Top comments (0)