Design a Navigation Bar with Animated Search Box Last Updated : 20 Jan, 2021 Comments Improve Suggest changes Like Article Like Report A navigation bar is one of the most important components of a website. It is the top bar that generally contains all the essential links in form of menus. In this tutorial, we are going to create a navigation bar with the following components: MenusAn animated search barLogin iconLogo But before moving on to the code let us see what languages we are going to use for the code, for the basic structure and the style we are going to use HTML CSS, and JQuery for the animated search bar. Approach: Link the jquery and the stylesheet with the HTML code.Design the jquery code for the animated search bar using the toggle class.Using the nav class to structure the elements to be included on the navigation bar.Design each element and the whole navigation bar as a whole using the CSS. Here is the implementation of the above approach: The code: HTML <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <!-- Linking the stylesheet --> <link rel="stylesheet" href= "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <!-- Linking the Jquery script --> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script> $(document).ready(function() { $(".fa-search").click(function() { $(".icon").toggleClass("active"); $("input[type='text']").toggleClass("active"); }); }); </script> <meta name="viewport" content= "width=device-width, initial-scale=1.0"> <script src="https://kit.fontawesome.com/a076d05399.js"></script> <style> /* Importing the fonts */ @import url( 'https://fonts.googleapis.com/css?family=Montserrat:400,500,600,700&display=swap'); * { margin: 0; padding: 0; outline: none; box-sizing: border-box; font-family: 'Montserrat', sans-serif; } /* Body of the page */ body { background: #f2f2f2; } /* Styling all the elements in nav as a whole */ nav { background: #037729; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; height: 70px; padding: 0 100px; } /* Styling the logo */ nav .logo { color: #fff; font-size: 30px; font-weight: 600; letter-spacing: -1px; } /* Styling all the nav items as a whole */ nav .nav-items { display: flex; flex: 1; padding: 0 0 0 200px; } /* Styling the list items in the nav tag */ nav .nav-items li { list-style: none; padding: 0 10px; } /* Styling each list items */ nav .nav-items li a { color: #fff; font-size: 15px; font-weight: 500; text-decoration: none; } /* Setting the hover colour on the list items*/ nav .nav-items li a:hover { color: #19191b; } nav .searchbar { position: relative; } /* Styling the search box where the input would be given */ nav .searchbar input[type="text"] { border: 0; padding: 0; width: 0px; height: 35px; border-radius: 3px; transition: all 0.3s ease; } /* Styling the search bar icon */ nav .searchbar .icon { display: flex; position: absolute; top: 0; right: 0; width: 35px; height: 100%; background: none; border-radius: 3px; color: #fff; transition: all 0.5s 0.3s ease; } nav .searchbar .icon i { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); cursor: pointer; } nav .searchbar .icon.active { background: #062333; transition: all 0.3s ease; } nav .searchbar input[type="text"].active { width: 250px; padding: 0 10px; transition: all 0.5s 0.2s ease; } nav .licon li { list-style: none; display: flex; } nav .licon li a { padding: 0 20px; } /* Changing the colour of the login icon when hovered over*/ .fa-user-circle:hover { color: #0e0d0d !important; } </style> </head> <body> <nav> <div class="logo"> GeeksforGeeks </div> <div class="nav-items"> <!-- The Menu items --> <li><a href="#">TUTORIALS</a></li> <li><a href="#">STUDENT</a></li> <li><a href="#">JOBS</a></li> <li><a href="#">COURSES</a></li> </div> <!-- Defining the search bars --> <div class="searchbar"> <input type="text" placeholder="search"> <div class="icon"> <i class="fas fa-search"></i> </div> </div> <!-- Defining the login button --> <div class="licon"> <li> <a href="#"> <i class="fas fa-user-circle fa-2x" style="color: white;"> </i> </a> </li> </div> </nav> </body> </html> Output: Only adding the HTML file along with the jQuery would produce the following result:Adding the CSS stylesheet along with the HTML and jquery code would produce the final result: Comment More infoAdvertise with us Next Article Design a Navigation Bar with Animated Search Box D debjani1413 Follow Improve Article Tags : Web Technologies Web Templates Similar Reads How to Create a Navigation Bar with CSS Flexbox? The navigation bar is a crucial aspect of modern web design. We can create a responsive navigation bar using CSS Flexbox, which provides a flexible and efficient way to layout elements, making it an excellent choice for creating navigation bars. Below are different possible ways for creating differe 5 min read How to Create a Navigation Menu with an Input Field Inside it? For some web applications, it might be necessary to include an input field within the navigation menu. This input field can serve as a search box allowing users to search for anything on the website. ApproachCreate a <nav> element to contain the navigation menu.Inside the <nav>, create a 2 min read How to Create a Navigation Bar with Material-UI ? The Navigation Bar Material UI component provides an efficient way to navigate through web application pages. React utilizes material UI NavBar for responsive and flexible navigation that is easy to implement and also provides animated transitions. ApproachTo create responsive top Navigation Bar Mat 3 min read How to Create a Navigation Bar with Icons in Tailwind CSS ? A navigation bar, commonly known as a nav bar, serves as a fundamental component of user interface design, facilitating seamless navigation across a website or application. Using the icons in the navigation bar gains a distinctive advantage in visual communication. Icons streamline navigation by usi 2 min read Foundation CSS Responsive Navigation Toggle with animation Foundation CSS is an open-source front-end framework that is used to create attractive responsive websites, emails, or apps quickly and easily. ZURB released it in September 2011. Numerous businesses, like Facebook, eBay, Mozilla, Adobe, and even Disney, use it. This platform, which resembles SaaS, 4 min read Create a Hoverable Side Navigation with HTML, CSS and JavaScript To create hoverable side navigation with icon on any website there is a need for two things HTML and CSS. If you want to attach the icons on the navigation bar then you need a font-awesome CDN link. These features make the website looks cool than a normal website where the nav-bar is old-school desi 4 min read How to Create a Responsive Navigation Bar with Dropdown? Dropdowns in navigation bars are used to organize and display a variety of menu options within a limited screen size. Dropdown allow users to access multiple pages or sections of a website without hampering the interface of a website. We will see how to create a responsive navigation bar with a drop 7 min read Design a Progress Bar with Smooth Animations using Tailwind CSS A progress bar is a type of component that tracks the percentage completion of a particular task and makes it visible to the users to enhance user interactivity. Steps to create the projectStep 1: Create a directory Progress Bar with files: index.html, style.css, and script.js for HTML, CSS, and Jav 3 min read How to Create Animated Navigation Bar with Hover Effect using HTML and CSS ? The Navigation bar or navbar or menu-bar is the most important component of any web or mobile application. The user can only navigate from one page to another page through this menu. It is usually provided at the top of the website to provide a better UX (user experience). Approach: The approach is 3 min read How To Build a Responsive Navigation Bar with Flexbox? A Responsive Navigation Bar is essential for modern web design to ensure users have a seamless experience across various devices, from desktops to mobile phones. Flexbox provides a powerful and straightforward way to create flexible and adaptable layouts. ApproachCreate a <nav> element for the 3 min read Like