<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Pagination - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Pagination - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Mon, 25 May 2026 22:38:41 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/pagination/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to create a pagination component ]]>
                </title>
                <description>
                    <![CDATA[ By Florin Pop The theme for week #17 of the Weekly Coding Challenge is: Pagination A Pagination Component is used on websites where you have more content available than you want to display at one time to the user so you'd split it on multiple pages. ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-create-a-pagination-component/</link>
                <guid isPermaLink="false">66d45f033a8352b6c5a2aa59</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Pagination ]]>
                    </category>
                
                    <category>
                        <![CDATA[ WeeklyCodingChallenge ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 12 Jul 2019 12:38:55 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2019/07/how-to-create-a-pagination.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Florin Pop</p>
<p>The <strong>theme</strong> for week #17 of the <a target="_blank" href="https://www.florin-pop.com/blog/2019/03/weekly-coding-challenge/">Weekly Coding Challenge</a> is:</p>
<h2 id="heading-pagination">Pagination</h2>
<p>A Pagination Component is used on websites where you have more content available than you want to display at one time to the user so you'd split it on multiple pages. By separating the content on different pages you are also saving a lot of bandwidth for the user because it won't be required to download all the information at once.</p>
<p>Some <strong>examples</strong> where you'd have a pagination: a blog with multiple pages, an online store with multiple products, etc.</p>
<p>In this article we're going to build this <a target="_blank" href="https://codepen.io/FlorinPop17/full/BgrvgX/">Pagination Component</a>:</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/FlorinPop17/embed/BgrvgX/" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p><strong>Note</strong>: the pagination is not functional, it's just for demo purposes (the visual). As an extra challenge, you can link this on a real website. </p>
<h2 id="heading-the-html">The HTML</h2>
<p>For the HTML structure we're going to use an <code>ul</code> as a wrapper with multiple <code>li</code>s. Each <code>li</code> will have an <code>a</code> tag within it because it's clickable (and semantic) and it'll send the user to the required page (if needed).</p>
<p>We're also using <a target="_blank" href="https://fontawesome.com/">FontAwesome</a> for the icons (left, right and the dots icons).</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"pagination"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">i</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"fas fa-chevron-left"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">i</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">i</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"fas fa-ellipsis-h"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">i</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>2<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"active"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>3<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>4<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>5<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">i</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"fas fa-ellipsis-h"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">i</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">i</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"fas fa-chevron-right"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">i</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
</code></pre>
<p>As you can see I also added an <code>.active</code> class to one of the <code>li</code>s - this is just to highlight the page we are on.</p>
<h2 id="heading-the-css">The CSS</h2>
<p>I'm going to paste the CSS and we'll discuss the important pieces afterwards.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.pagination</span> {
    <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid <span class="hljs-number">#aaa</span>;
    <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">4px</span>;
    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">list-style-type</span>: none;
    <span class="hljs-attribute">overflow</span>: hidden;
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">0</span>;
}

<span class="hljs-selector-class">.pagination</span> <span class="hljs-selector-tag">li</span> {
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#fff</span>;
}

<span class="hljs-selector-class">.pagination</span> <span class="hljs-selector-tag">li</span><span class="hljs-selector-pseudo">:hover</span>,
<span class="hljs-selector-class">.pagination</span> <span class="hljs-selector-tag">li</span><span class="hljs-selector-class">.active</span> {
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#aaa</span>;
}

<span class="hljs-selector-class">.pagination</span> <span class="hljs-selector-tag">li</span> <span class="hljs-selector-tag">a</span> {
    <span class="hljs-attribute">color</span>: <span class="hljs-number">#555</span>;
    <span class="hljs-attribute">display</span>: block;
    <span class="hljs-attribute">font-weight</span>: bold;
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">10px</span> <span class="hljs-number">15px</span>;
    <span class="hljs-attribute">text-decoration</span>: none;
}

<span class="hljs-selector-class">.pagination</span> <span class="hljs-selector-tag">li</span><span class="hljs-selector-pseudo">:hover</span> <span class="hljs-selector-tag">a</span>,
<span class="hljs-selector-class">.pagination</span> <span class="hljs-selector-tag">li</span><span class="hljs-selector-class">.active</span> <span class="hljs-selector-tag">a</span> {
    <span class="hljs-attribute">color</span>: <span class="hljs-number">#fff</span>;
}
</code></pre>
<p>Things to note:</p>
<ol>
<li>The <code>ul</code> / <code>.pagination</code> it's a <strong>flex</strong> container - this is because it's much easier to position the <code>li</code>s within it by using flexbox (and who doesn't like flexbox? ?)</li>
<li>Because we have a little bit of a <code>border-radius</code> on the <code>ul</code> we need to add <code>overflow: hidden</code> because otherwise the <code>li</code>'s corner will be visible on top of the border of the <code>ul</code> (remove the overflow and you'll see what I mean)</li>
<li>We have the same styling on <code>li:hover</code> as on <code>li.active</code>, but you can differentiate between these to states if you want</li>
</ol>
<p>Other than that, I believe it's pretty straightforward, but if you have any questions please let me know. ?</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>There are other variants of paginations out there on the web. Find one you like and convert it to code.</p>
<p>Make sure you share with me what you've built!</p>
<p>Happy Coding! ?</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
