Create an Infinite Scroll Page using HTML CSS & JavaScript Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report In this article, we will create an infinite scroll page using HTML, CSS, and JavaScript. Infinite scrolling allows you to load and display content as the user scrolls down the page, providing a seamless browsing experience. We'll fetch and append new content dynamically as the user reaches the end of the current content. Preview Image:Output PreviewApproach:We'll build a basic web page with a container to display content and a loader indicator. JavaScript will handle fetching and appending new content when the user scrolls to the bottom of the page. When you open the HTML file in your web browser, you'll immediately notice the initial content loading on the page. As you gracefully scroll down, the magic happens: new items seamlessly appear, dynamically loaded, and elegantly displayed. During this process, a loading indicator gracefully shows up, politely indicating that fresh data is being fetched.In essence, this code crafts an infinite scroll page where new content materializes as you gracefully navigate downward. The charm lies in its adaptability - you can effortlessly tailor both the content and style to harmonize with your project's unique requirements.This practical example serves as a foundational introduction to crafting an infinite scroll page using HTML, CSS, and JavaScript. From this solid foundation, you have the creative liberty to refine it further, perhaps integrating real data from an API or refining the visual aesthetics to harmonize seamlessly with your project's vision.Project Structure:Project StructureExample: Below is the basic implementation of the above project. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content-after-loading="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" href="style.css" /> <title> Create an Infinite Scroll Page using HTML CSS & JavaScript </title> </head> <body> <div id="content-before-loading"></div> <script src="script.js"></script> </body> </html> CSS body { font-family: cursive; margin: 0; padding: 0; background-color: #968d8d; } .sub-block { border: 1px solid #030303; padding: 20px; margin: 10px 0; height: 50px; text-align: center; } #content-before-loading { text-align: center; display: none; font-size: 16px; margin-top: 20px; max-width: 600px; margin: 20px auto; padding: 20px; background-color: #fff; } JavaScript const before_loading = document.getElementById("content-before-loading"); before_loading.style.display = "block"; let c = 0; function getInformation() { setTimeout(() => { for (let i = 0; i < 10; i++) { const new_div = document.createElement("div"); new_div.className = "sub-block"; new_div.innerHTML = `Card ${c}${i}`; before_loading.appendChild(new_div); } c++; }, 1000); } window.addEventListener("scroll", () => { if ( document.documentElement.scrollTop + document.documentElement.clientHeight >= document.documentElement.scrollHeight ) { getInformation(); } }); getInformation(); Output: Output Comment More infoAdvertise with us Next Article Create an Infinite Scroll Page using HTML CSS & JavaScript S satejbpatil Follow Improve Article Tags : JavaScript Web Technologies Geeks Premier League JavaScript-Projects Geeks Premier League 2023 +1 More Similar Reads 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 Create a Pagination using HTML CSS and JavaScript In this article, we will create a working pagination using HTML, CSS, and JavaScript. Pagination, a widely employed user interface pattern, serves the purpose of dividing extensive data or content into more manageable portions. It allows users the ability to effortleÂssly navigate through numerou 5 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 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 How to create Infinite Scrolling using onScroll Event in JavaScript? We have seen many shopping sites that list some limited number of products(using a back-end API) when we open the website and scroll down to the bottom, we see that more products are fetched and displayed, and as we scroll even further even more products are loaded and fetched and it keeps happening 3 min read Create a Pagination Component using HTML CSS and JavaScript In this article, we are going to create a pagination component using HTML, CSS, and JavaScript. Websites may need multiple pages to display the items for easier navigation and better user experiences. If you are looking to display large amounts of data on your site, like a blog, charts, or graphs th 3 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 Reverse Scrolling Effect using HTML and CSS Creating an attractive UI with a reverse scroll effect can be an engaging design. The Reverse Scrolling effect facilitates a unique and visually interactive experience for users, which breaks the conventional top-down scrolling system to which the user is accustomed. In this article, we'll create a 2 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 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 Like