How to Create Shrink Header on Scroll using HTML, CSS and JavaScript ? Last Updated : 05 May, 2025 Comments Improve Suggest changes Like Article Like Report 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 navbar looks attractive on a site. By using JavaScript you can easily make the navigation bar shrinkable when the user scrolls down.Creating Structure: In the HTML section, we will create a basic website structure for the shrinkable navbar and when the user scrolls down the page it will display the effect. Designing Structure: In CSS and JavaScript section, we will design the structure of the navigation bar and then the scroll-down effect on the navbar using JavaScript. html <!DOCTYPE html> <html> <head> <meta name="viewport" content ="width=device-width, initial-scale=1"> <title> How to Create Shrink Header on Scroll using HTML, CSS and JavaScript ? </title> </head> <body> <!-- Navlist of header --> <div id="navlist"> <a href="#default" id="logo"> GeeksforGeeks </a> <div id="navlist-right"> <a href="#home">Home</a> <a href="#about">Our Products</a> <a href="#about">Careers</a> <a href="#contact">Contact US</a> <a href="#about">About US</a> </div> </div> <!-- Page Content --> <div class="content"> <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> </div> </body> </html> CSS <style> * { box-sizing: border-box; } body { margin: 0; } /* Navlist designing */ #navlist { overflow: hidden; background-color: #0074D9; padding: 90px 10px; transition: 0.4s; position: fixed; width: 100%; top: 0; z-index: 1; } #navlist a { float: left; color: white; text-align: center; padding: 12px; text-decoration: none; font-size: 18px; line-height: 25px; border-radius: 4px; } #navlist #logo { font-size: 35px; font-weight: bold; transition: 0.4s; } #navlist a:hover { color: #01FE06; } #navlist-right { float: right; } /* Content design */ .content { margin-top:220px; padding:15px 15px 1800px; font-size:22px; } </style> JavaScript <script> // Scrolls down 90px from the top of // the document, to resize the navlist // padding and the title font-size window.onscroll = function() { scrollFunction() }; function scrollFunction() { if (document.body.scrollTop > 90 || document.documentElement.scrollTop > 90) { document.getElementById("navlist") .style.padding = "25px 10px"; document.getElementById("logo") .style.fontSize = "24px"; } else { document.getElementById("navlist") .style.padding = "90px 10px"; document.getElementById("logo") .style.fontSize = "35px"; } } </script> Output: Comment More infoAdvertise with us Next Article How to Create Shrink Header on Scroll using HTML, CSS and JavaScript ? S Sabya_Samadder Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Projects Similar Reads How to Create a Fixed/Sticky Header on Scroll with CSS and JavaScript? A fixed or sticky header remains at the top of the webpage when the user scrolls down. This functionality enhances navigation and user experience by keeping important links always visible. In this article, we will explore the approach to creating a fixed/sticky header on scroll using CSS and JavaScr 3 min read How to Create Sticky Header/Footer on a Web Page using HTML CSS and JavaScript? When designing a website, it's essential to consider the sticky header and footer. These elements enhance the user experience by keeping important navigation links accessible as users scroll. This article explores creating sticky headers and footers with CSS.We can do this by using the following CSS 7 min read How to Create Scroll Indicator using HTML CSS and JavaScript ? Scroll Indicator is a progress bar that represents how much a page has been scrolled. When we scroll down the bar fills up and when we scroll up the bar amount reduces. Approach: Now, we will create a basic webpage with text to enable scrolling and then use JavaScript to make the scroll indicator wo 3 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 Horizontal Scroll Snap Using HTML and CSS ? In this project, we are going to create a simple Horizontal Scroll Snap by using HTML and CSS only.Glimpse of Project Approach: The best way to animate the HTML objects is by using CSS classes and by setting the transitions at different stages.HTML code:Create an HTML file (index.html).Link the CSS 2 min read How to Create Tab Headers using CSS & JavaScript? Tab headers are a commonly used user interface element in web development. They provide a way to organize content into distinct sections, allowing users to switch between them easily. Each tab represents a different category or topic, and clicking on a tab displays the corresponding content while hi 2 min read How to Create Image Magnifier using HTML CSS and JavaScript? An image magnifier is a feature that allows users to zoom into specific parts of an image, simulating a magnifying glass effect. Itâs created using HTML for structure, CSS for styling, and JavaScript to control the zoom functionality dynamically on hover or click.There are two methods to create an i 2 min read Slide Down a Navigation Bar on Scroll using HTML, CSS and JavaScript 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 d 4 min read How to create Non-Rectangular Header using HTML & CSS ? In this article, we are going to create a Non-Rectangular-header using the basics of HTML and CSS. Approach: Create a header using <header> tag.Create a div for adding the content for the header.Use clip-path() function to give a particular shape to the header. HTML Code: Create an HTML file ( 1 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 Like