<?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[ progress bar - 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[ progress bar - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Thu, 04 Jun 2026 22:48:24 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/progress-bar/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to create a Custom Progress Bar ]]>
                </title>
                <description>
                    <![CDATA[ By Florin Pop Originally published on www.florin-pop.com The theme for week #14 of the Weekly Coding Challenge is: Progress Bar A progress bar is used to show how far a user action is still in process until it's completed. A good example is a downloa... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-create-a-custom-progress-bar/</link>
                <guid isPermaLink="false">66d45f004a7504b7409c33e9</guid>
                
                    <category>
                        <![CDATA[ WeeklyCodingChallenge ]]>
                    </category>
                
                    <category>
                        <![CDATA[ coding challenge ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ progress bar ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 13 Jun 2019 04:02:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2019/06/how-to-create-a-custom-progress-bar.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Florin Pop</p>
<p><em>Originally published on <a target="_blank" href="https://www.florin-pop.com/blog/2019/06/how-to-create-a-custom-progress-bar/">www.florin-pop.com</a></em></p>
<p>The <strong>theme</strong> for week #14 of the <a target="_blank" href="https://florin-pop.com/blog/2019/03/weekly-coding-challenge/">Weekly Coding Challenge</a> is:</p>
<h2 id="heading-progress-bar">Progress Bar</h2>
<p>A progress bar is used to show how far a user action is still in process until it's completed. A good example is a download progress bar which shows you how much of the file is downloaded already (or it could also be an upload progress bar if you upload files ?).</p>
<p>In this article we're going to build this kind of a <a target="_blank" href="https://codepen.io/FlorinPop17/full/jjPWbv/">Progress Bar</a>:</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/FlorinPop17/embed/jjPWbv/" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<h2 id="heading-the-html">The HTML</h2>
<p>For the HTML structure we need two things:</p>
<ol>
<li>a <em>container</em> which will display the total length (100%) of the progress bar - <code>.progress-bar</code></li>
<li>the actual progress element which will basically track the current progress (e.g. 20%) - <code>.progress</code></li>
</ol>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"progress-bar"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">data-size</span>=<span class="hljs-string">"20"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"progress"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>As you can see the <code>.progress</code> div has a <code>data-size</code> attribute. This will be used in <strong>JavaScript</strong> to actually set the <code>width</code> of the progress. You'll see in a moment what I mean, but first let's style these two elements. ?</p>
<h2 id="heading-the-css">The CSS</h2>
<pre><code class="lang-css"><span class="hljs-selector-class">.progress-bar</span> {
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#fefefe</span>;
    <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">3px</span>;
    <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">0</span> <span class="hljs-number">1px</span> <span class="hljs-number">3px</span> <span class="hljs-built_in">rgba</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0.2</span>);
    <span class="hljs-attribute">margin</span>: <span class="hljs-number">15px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">30px</span>;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">500px</span>;
    <span class="hljs-attribute">max-width</span>: <span class="hljs-number">100%</span>;
}

<span class="hljs-selector-class">.progress</span> {
    <span class="hljs-attribute">background</span>: <span class="hljs-number">#ad5389</span>;
    <span class="hljs-attribute">background</span>: <span class="hljs-built_in">-webkit-linear-gradient</span>(to bottom, #<span class="hljs-number">3</span>c1053, #ad5389);
    <span class="hljs-attribute">background</span>: <span class="hljs-built_in">linear-gradient</span>(to bottom, #<span class="hljs-number">3</span>c1053, #ad5389);
    <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">3px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">30px</span>;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">transition</span>: width <span class="hljs-number">0.5s</span> ease-in;
}
</code></pre>
<p>Few things to note regarding the above CSS:</p>
<ol>
<li>both elements are rectangles that have the same height (<code>30px</code>) and the same <code>border-radius</code></li>
<li>initially the <code>.progress</code> width it set to <code>0</code> and we'll update this in the <strong>JavaScript</strong> code below</li>
<li>also the <code>.progress</code> has a nice <code>linear-gradient</code> from <a target="_blank" href="https://uigradients.com/">uiGradients</a></li>
<li>the <code>transition</code> added to the <code>.progress</code> is used to create a nice animation when the value of it's <code>data-size</code> attribute is dynamically changed</li>
</ol>
<h2 id="heading-the-javascript">The JavaScript</h2>
<p>For this we'll need to loop over all the <code>.progress</code> elements (in our example is only one, but you can add multiple ones in an app) to get their <code>data-set</code> value and to set it as their width. We'll use percentage (<code>%</code>) in this case.</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> progress_bars = <span class="hljs-built_in">document</span>.querySelectorAll(<span class="hljs-string">'.progress'</span>);

progress_bars.forEach(<span class="hljs-function"><span class="hljs-params">bar</span> =&gt;</span> {
    <span class="hljs-keyword">const</span> { size } = bar.dataset;
    bar.style.width = <span class="hljs-string">`<span class="hljs-subst">${size}</span>%`</span>;
});
</code></pre>
<p>We're using a little bit of <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment">Object Destructuring</a>.</p>
<p><code>const { size } = bar.dataset</code></p>
<p>is the same as:</p>
<p><code>const size = bar.dataset.size</code></p>
<p>but you might know that already ?.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>There are multiple things you could do to improve this component. Some of which are:</p>
<ol>
<li>Add multiple color variants via different <em>classes</em></li>
<li>Add the percentage value</li>
<li>Make it animate dynamically by changing the size value.</li>
</ol>
<p>I hope you enjoyed it and make sure you share with me what you're creating!</p>
<p>Happy Coding! ?</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
