As website developers, we often want to display progress to our users in a visual way. One way to do this is by creating a progress bar. In this tutorial, we’ll show you how to create a basic progress bar using HTML and CSS.
HTML Structure
First, let’s start by setting up the HTML structure for our progress bar. We’ll use two div
elements to create the progress bar container and the progress itself.
<div class="progress-bar">
<div class="progress"></div>
</div>
We’ve added a class name to each element to make it easier to style them with CSS later on.
The outer div
with class progress-bar
serves as the container for the progress bar, while the inner div
with class progress
represents the actual progress.
Styling the Progress Bar
Now that we have the HTML structure set up, we can move on to styling the progress bar with CSS.
.progress-bar {
width: 100%;
height: 20px;
background-color: #ddd;
border-radius: 10px;
}
.progress {
height: 100%;
background-color: #4CAF50;
border-radius: 10px;
width: 50%;
}
We’ve set the width of the progress-bar
to 100%
to make it fill up the entire container. We’ve also set the height to 20px
and added a gray background-color
of #ddd
. The border-radius
of 10px
gives the progress bar rounded edges.
For the progress
element, we’ve set the height to 100%
so that it fills up the entire progress-bar
. We’ve given it a green background-color
of #4CAF50
to represent the progress. The border-radius
of 10px
gives the progress bar rounded edges, just like the progress-bar
.
Finally, we’ve set the width of the progress
element to 50%
. This means that the progress bar will be filled up to 50%
of its width, representing 50%
progress. You can adjust this value to reflect the progress percentage you want to display.
Conclusion
That’s it! With just a few lines of HTML and CSS, you can create a basic progress bar to display progress to your users. Of course, you can customize the design and layout of the progress bar to match your website’s style.
Facebook Comments