Slide Down a Navigation Bar on Scroll using HTML, CSS and JavaScript Last Updated : 27 Sep, 2021 Comments Improve Suggest changes Like Article Like Report To create a slide down navigation bar you need to use HTML, CSS, and JavaScript. HTML will make the structure of the body, CSS will make it looks good. This kind of sliding navbar looks attractive on a site. By using JavaScript you can easily make the navigation bar slideable when the user scrolls down. Creating Structure: In this section, we will create a basic website structure for the slide down navbar when the user scrolls down the page it will display the effect.  HTML code to make the structure: HTML <!DOCTYPE html> <html> <head> <title> Slide Down a Navigation Bar on Scroll using HTML CSS and JavaScript </title> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <!-- logo with tag --> <article> <h1 style="color:green;"> GeeksforGeeks </h1> <b> A Computer Science Portal for Geeks </b> <p> How many times were you frustrated while looking out for a good collection of programming/algorithm/interview questions? What did you expect and what did you get? This portal has been created to provide well written, well thought and well explained solutions for selected questions. </p> </article> <!-- Navbar items --> <div id="navlist"> <a href="#">Home</a> <a href="#">About Us</a> <a href="#">Our Products</a> <a href="#">Careers</a> <a href="#">Contact Us</a> </div> <!-- for creating scroll --> <div class="scrollable" style="padding:15px 15px 4500px;"> </div> </body> </html> Designing Structure: In the previous section, we have created the structure of the basic website. In this section, we will design the structure for the navigation bar and then scroll down the effect on the navbar using JavaScript. CSS code to look good the structure: CSS <style> /* styling article tag component */ article { position: fixed; margin-left: 10px; } /* styling navlist */ #navlist { background-color: #0074D9; position: fixed; left: 45%; top: -60px; width: auto; display: block; transition: top 0.3s; } /* styling navlist anchor element */ #navlist a { float: left; display: block; color: #f2f2f2; text-align: center; padding: 12px; text-decoration: none; font-size: 15px; } /* hover effect of navlist anchor element */ #navlist a:hover { background-color: #ddd; color: black; } </style> JavaScript code for the animation on the menu: JavaScript <script> // When the user scrolls down then // slide down the navbar window.onscroll = function() { scroll() }; function scroll() { if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) { document.getElementById("navlist").style.top = "0"; } else { document.getElementById("navlist").style.top = "-60px"; } } </script> Combining the HTML, CSS, and JavaScript code: This example is the combination of the above sections. HTML <!DOCTYPE html> <html> <head> <title> Slide Down a Navigation Bar on Scroll using HTML CSS and JavaScript </title> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> /* styling article tag component */ article { position: fixed; margin-left: 10px; } /* styling navlist */ #navlist { background-color: #0074D9; position: fixed; left: 45%; top: -60px; width: auto; display: block; transition: top 0.3s; } /* styling navlist anchor element */ #navlist a { float: left; display: block; color: #f2f2f2; text-align: center; padding: 12px; text-decoration: none; font-size: 15px; } /* hover effect of navlist anchor element */ #navlist a:hover { background-color: #ddd; color: black; } </style> </head> <body> <!-- logo with tag --> <article> <h1 style="color:green;"> GeeksforGeeks </h1> <b> A Computer Science Portal for Geeks </b> <p> How many times were you frustrated while looking out for a good collection of programming/algorithm/interview questions? What did you expect and what did you get? This portal has been created to provide well written, well thought and well explained solutions for selected questions. </p> </article> <!-- Navbar items --> <div id="navlist"> <a href="#">Home</a> <a href="#">About Us</a> <a href="#">Our Products</a> <a href="#">Careers</a> <a href="#">Contact Us</a> </div> <!-- for creating scroll --> <div class="scrollable" style="padding:15px 15px 4500px;"> </div> <script> // When the user scrolls down then // slide down the navbar window.onscroll = function() { scroll() }; function scroll() { if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) { document.getElementById("navlist").style.top = "0"; } else { document.getElementById("navlist").style.top = "-60px"; } } </script> </body> </html> Output:  Comment More infoAdvertise with us Next Article Slide Down a Navigation Bar on Scroll using HTML, CSS and JavaScript S Sabya_Samadder Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Projects Similar Reads How to Create Full Screen Overlay Navigation Bar using HTML CSS and JavaScript ? Create a full screen Navigation Bar: In this article, you will learn how to create a full-screen navbar for your website. There are three methods to create a full screen overlay navigation bar which are listed below: From Left From top No animation- Just show You will be required to create two divs. 4 min read How to Create Shrink Header on Scroll using HTML, CSS and JavaScript ? The Shrink Navigation bar works when the user scrolls down the page. In this article, we will use HTML, CSS, and JavaScript to design a shrink navigation bar. HTML is used to create the structure, and CSS is used to set the style of the HTML structure to make it looks good. This kind of shrinking na 3 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 revealing sidebar using HTML CSS and JavaScript? A revealing sidebar is a hidden UI element that becomes visible upon user interaction, such as clicking or swiping, providing navigation links. The content of the page will rotate and the navigation bar will reveal itself when the menu button is clicked. ApproachCreate an HTML file with headings and 3 min read Create a Mobile Toggle Navigation Menu using HTML, CSS and JavaScript To create a Mobile Toggle Navigation Menu you need HTML, CSS, and JavaScript. If you want to attach the icons with the menu then you need a font-awesome CDN link. This article is divided into two sections: Creating Structure and Designing Structure.A glimpse of complete Navigation: Creating Structur 3 min read Scrollspy using HTML CSS and JavaScript In this article, we will learn about Scrollspy which is a popular feature used in modern web applications. It is used to highlight and allow to navigate through different sections of long web pages as the user scrolls. It increases the interaction between the user and the web application by providin 5 min read How to Create a Change Background on Scroll using HTML CSS and JavaScript ? In this article, we will try to change the background color of the container once the scroll occurs. If a user scrolls down the page the background color will be changed. We will use the below approach to accomplish this task.Using the scroll event on the window objectIn this approach, we will use t 6 min read How to create a Landing page using HTML CSS and JavaScript ? A landing page, also referred to as a lead capture page, static page, or destination page, serves a specific purpose and typically appears as a result of online advertising or search engine optimization efforts. Unlike a homepage, a landing page is stripped of distractions and focuses on capturing v 7 min read Design a Toggleable Sidebar using HTML CSS and JavaScript In this article, we will create a toggleable sidebar navigation menu using HTML, CSS, and JavaScript. The navigation menu allows users to open and close a sidebar to access various sections of a website. When the user clicks on a navigation item, the corresponding content is displayed in the main co 3 min read Design a Navigation Bar with Toggle Dark Mode in HTML CSS & JavaScript One can create a navigation bar with a toggle switch for dark mode using HTML, CSS, and JavaScript. If we use the dark mode effect in our website then it can attract user attention and users can use our website in any situation. With the help of JavaScript, we'll implement the functionality to toggl 6 min read Like