Create a Pagination Component using HTML CSS and JavaScript Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report 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 that show information about the same data set, you will surely need to split these data into various pages for improved readability. Pagination comes to the rescue in such a problem. It is a connected sequence of web pages that have similar content. The content of a section is divided into multiple pages with the help of pagination. ApproachWe initialize the constants for "itemsPerPage" and the "totalItems". We set up variables to keep track of the current page.We create a function to generate the content based on the current page. We also update the HTML content in it.We create a function to generate pagination links and arrow buttons.We attach click-based event listeners to pagination links and arrow buttons. When the pagination link is created, update the current page and update the paginationNow we call the content and pagination function. Example: This example illustrates the creation of the Pagination Component using HTML CSS & JavaScript. HTML <!-- index.html --> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="style.css"> <title>Pagination Example</title> </head> <body> <div class="pagination-container"> <div id="pagination" class="pagination"> </div> <div id="content" class="content"> </div> </div> <script src="script.js"></script> </body> </html> CSS /* styles.css */ body { font-family: Arial, sans-serif; margin: 0; padding: 0; display: flex; align-items: center; justify-content: center; height: 100vh; background-color: #3498db; } .pagination-container { text-align: center; } .pagination { display: inline-block; padding: 16px; } .pagination a { color: #fff; background-color: #2ecc71; border: 1px solid #2ecc71; border-radius: 8px; padding: 10px 20px; margin: 5px; text-decoration: none; font-size: 16px; transition: background-color 0.3s; } .pagination a.active { background-color: #27ae60; border: 1px solid #27ae60; } .pagination a:hover:not(.active) { background-color: #27ae60; border: 1px solid #27ae60; color: #fff; } .pagination .arrow { font-size: 20px; font-weight: bold; margin: 0 10px; cursor: pointer; color: #fff; } .content { padding: 20px; background-color: #fff; border-radius: 8px; margin-top: 20px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } JavaScript // script.js document.addEventListener("DOMContentLoaded", function () { const contentDiv = document.getElementById("content"); const paginationDiv = document.getElementById("pagination"); const itemsPerPage = 3; const totalItems = 10; let currentPage = 1; function generateContent(page) { contentDiv.innerHTML = ""; for (let i = (page - 1) * itemsPerPage + 1; i <= page * itemsPerPage; i++) { contentDiv.innerHTML += `<p>Item ${i}: This is some content for item ${i}.</p>`; } } function generatePagination() { const totalPages = Math.ceil(totalItems / itemsPerPage); paginationDiv.innerHTML = ""; const prevArrow = document.createElement("span"); prevArrow.className = "arrow"; prevArrow.textContent = "←"; prevArrow.addEventListener("click", function () { if (currentPage > 1) { currentPage--; generateContent(currentPage); generatePagination(); } }); paginationDiv.appendChild(prevArrow); for (let i = 1; i <= totalPages; i++) { const link = document.createElement("a"); link.href = "#"; link.textContent = i; if (i === currentPage) { link.classList.add("active"); } link.addEventListener("click", function () { currentPage = i; generateContent(currentPage); generatePagination(); }); paginationDiv.appendChild(link); } const nextArrow = document.createElement("span"); nextArrow.className = "arrow"; nextArrow.textContent = "→"; nextArrow.addEventListener("click", function () { if (currentPage < totalPages) { currentPage++; generateContent(currentPage); generatePagination(); } }); paginationDiv.appendChild(nextArrow); } generateContent(currentPage); generatePagination(); }); Output: Comment More infoAdvertise with us Next Article Create a Pagination Component using HTML CSS and JavaScript C chetansingh7 Follow Improve Article Tags : JavaScript Web Technologies Geeks Premier League JavaScript-Projects Geeks Premier League 2023 +1 More Similar Reads 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 Create an Infinite Scroll Page using HTML CSS & JavaScript 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 o 2 min read How to Create a Portfolio Website using HTML CSS and JavaScript ? A portfolio website is a website that represents you online on the web pages. It contains different sections like Introduction to Yourself, About You, Your Services, Your Contact Details, and Your Portfolio. We are going to build all of the sections with an interactive and attractive web design that 15+ min read How to make a Pagination using HTML and CSS ? Creating pagination is quite simple, you can easily do that by using Bootstrap, and JavaScript. However, in this article, we will use HTML and CSS to create pagination. Pagination is helpful when the website contains lots of content on a single page, and a single page will not look good with all th 3 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 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 make Incremental and Decremental counter using HTML, CSS and JavaScript ? While visiting different shopping websites like Flipkart and Amazon you have seen a counter on each product, that counter is used to specify the quantity of that product. Hence, the counter is a very useful part of many websites. In this article, we will design a counter using HTML, CSS, and JavaScr 2 min read Pagination Component using React Hooks Pagination on websites refers to the way of displaying a large set of data in smaller chunks. In React, it's super easy to create a pagination component with the help of the `useEffect` and `useState` hooks. we will create a pagination component using React hooks. Output Preview: Let us have a look 3 min read Angular MDBootstrap Pagination Component MDBootstrap is a Material Design and bootstrap-based Angular UI library that is used to make good looking webpages with its seamless and easy-to-use component. In this article, we will know how to use Pagination Component in Angular MDBootstap. Pagination Component allows the user to navigate data b 3 min read ReactJS UI Ant Design Pagination Component Ant Design Library has this component pre-built, and it is very easy to integrate as well. Pagination Component allows the user to show the page number and switch between pages easily with the next and previous button. We can use the following approach in ReactJS to use the Ant Design Pagination Com 3 min read Like