- Published on
Best Ways To Create A Progress Slider Component With Tailwind CSS

- What is Tailwind CSS?
- The description of Progress Slider Component ui component
- Why use Tailwind CSS to build a Progress Slider Component ui component?
- The preview of Progress Slider Component ui component
- The source code of Progress Slider Component ui component
- How to build a Progress Slider Component with Tailwind CSS?
- Install tailwind css of verion 3.0.18
- All the unility class needed to build a Progress Slider Component component
- 30 steps to build a Progress Slider Component component with Tailwind CSS
- Conclusion
What is Tailwind CSS?
Tailwind CSS is a utility-first CSS framework that focuses on creating personalized user interfaces quickly. It can gives you all the building blocks you are able to create personalized designs without having to fight to override irritating opinionated styles. Also, Tailwind CSS is a highly configurable, low-level CSS framework.
The description of Progress Slider Component ui component
Tailwind + alpinejs progress slider example. also see on codepen.io/egoistdeveloper/pen/joyrngq
Why use Tailwind CSS to build a Progress Slider Component ui component?
- It can make the building process of Progress Slider Component ui component faster and more easily.
- Enables building complex responsive layouts and components freely.
- Minimum lines of CSS code in Progress Slider Component component file.
The preview of Progress Slider Component ui component
Free download of the Progress Slider Component's source code
The source code of Progress Slider Component ui component
<!-- AlpineJS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/alpinejs/3.8.1/cdn.min.js" defer></script>
<style>
/* Slider */
.x-slider * {
width: 350px !important;
}
.x-slider input::-webkit-slider-thumb {
width: 20px;
height: 20px;
border-radius: 50%;
background-color: #636363;
border: 5px solid #24c55d;
box-shadow: 0px 0px 40px -4px rgba(0, 0, 0, 0.76);
transition: all 0.1s ease-in-out;
outline: none;
appearance: none;
}
.x-slider input::-webkit-slider-thumb:hover {
border-color: #1bb350;
}
</style>
<!-- Story Bar Container -->
<div class="flex flex-col items-center justify-center mt-52">
<!-- App -->
<div class="bg-white p-10 rounded-md shadow-lg" x-cloak x-data="appData()" x-init="appInit()">
<!-- Player -->
<div class="relative">
<!-- Player Slider Container -->
<div class="x-slider flex relative my-3">
<!-- Player Slider -->
<div class="x-slider inline justify-center rounded-md">
<!-- Range Input -->
<input class="absolute bg-transparent rounded-md
z-10 h-1 w-80 outline-0 appearance-none" type="range"
step="1" min='0' max="100" value="0"
x-model="sliderValue"
x-on:change.debounce="sliderProgressTime = sliderProgressToTime(sliderValue, songLength)">
<!-- Slider Placeholder -->
<div class="absolute z-0 w-80 h-0.5 mt-0.5 rounded-md bg-gray-500/70"></div>
<!-- Progress -->
<div class="absolute z-0 w-80 h-1.5 rounded-md bg-green-600
bg-gradient-to-r from-emerald-700 to-green-500"
x-bind:style="'width: ' + (sliderValue * 3.5) + 'px !important; '"></div>
<!-- x-slider is width 350px -->
</div>
</div>
<!-- Duration Container -->
<div class="flex flex-row flex-grow justify-start px-0.5">
<!-- Current Time -->
<div class="text-gray-500/90 text-sm select-none" x-text="sliderProgressTime"></div>
<!-- Grow Space -->
<div class="grow"></div>
<!-- Total Time -->
<div class="text-gray-400/90 text-sm select-none pr-1" x-text="secondsToDuration(songLength)"></div>
</div>
</div>
</div>
<!-- Notes -->
<span class="text-center font-bold my-20">
<a href="https://egoistdeveloper.github.io/twcss-to-sass-playground/" target="_blank" class="text-blue-600">
Convetert to SASS
</a>
</span>
</div>
<script>
function appData() {
return {
sliderValue: 50,
songLength: 250,
sliderProgressTime: '00:00',
appInit() {
this.sliderProgressTime = this.sliderProgressToTime(this.sliderValue, this.songLength);
},
/*
* Convert slider value to time
*/
secondsToDuration(seconds) {
var minutes = Math.floor(seconds / 60).toFixed(0),
seconds = Math.floor(seconds % 60).toFixed(0);
return minutes + ":" + (seconds < 10 ? "0" : "") + seconds;
},
/*
* Slider progress value to time
*/
sliderProgressToTime(sliderValue, songLength) {
return this.secondsToDuration((songLength / 100) * sliderValue);
}
}
}
</script>
How to build a Progress Slider Component with Tailwind CSS?
Install tailwind css of verion 3.0.18
Use the script
html tag to import the script of Tailwind CSS of the version 3.0.18
<script src="https://cdn.tailwindcss.com"></script>
All the unility class needed to build a Progress Slider Component component
flex
flex-col
mt-52
bg-white
p-10
relative
my-3
inline
absolute
bg-transparent
z-10
h-1
w-80
z-0
h-0.5
mt-0.5
bg-gray-500/70
h-1.5
bg-gradient-to-r
flex-row
flex-grow
justify-start
px-0.5
text-gray-500/90
text-sm
text-gray-400/90
pr-1
text-center
my-20
text-blue-600
30 steps to build a Progress Slider Component component with Tailwind CSS
Use
flex
to create a block-level flex container.Use
flex
to create a block-level flex container.Control the margin on top side of an element to 13rem using the
mt-52
utilities.Control the background color of an element to white using the
bg-white
utilities.Control the padding on all sides of an element to 2.5rem using the
p-10
utilities.Use
relative
to position an element according to the normal flow of the document.Control the vertical margin of an element to 0.75rem using the
my-3
utilities.Use
inline
utilities to control the flow of text inside the element to wrap normally.Use
absolute
to position an element outside of the normal flow of the document, causing neighboring elements to act as if the element doesn’t exist.Control the background color of an element to transparent using the
bg-transparent
utilities.Control the stack order (or three-dimensional positioning) of an element to 10 in Tailwind, regardless of order it has been displayed, using the
z-10
utilities.Use
h-1
to set an element to a fixed height(0.25rem).Use
w-80
to set an element to a fixed width(20rem).Control the stack order (or three-dimensional positioning) of an element to 0 in Tailwind, regardless of order it has been displayed, using the
z-0
utilities.Use
h-0.5
to set an element to a fixed height(0.5).Control the margin on top side of an element to 0.5 using the
mt-0.5
utilities.Control the background color of an element to gray-500/70 using the
bg-gray-500/70
utilities.Use
h-1.5
to set an element to a fixed height(1.5).Control the background color of an element to gradient-to-r using the
bg-gradient-to-r
utilities.Use
flex
to create a block-level flex container.Use
flex
to create a block-level flex container.Use
justify-start
to justify items against the start of the container’s main axis.Control the horizontal padding of an element to 0.5 using the
px-0.5
utilities.Control the text color of an element to gray-500/90 using the
text-gray-500/90
utilities.Control the text color of an element to sm using the
text-sm
utilities.Control the text color of an element to gray-400/90 using the
text-gray-400/90
utilities.Control the padding on right side of an element to 0.25rem using the
pr-1
utilities.Control the text color of an element to center using the
text-center
utilities.Control the vertical margin of an element to 5rem using the
my-20
utilities.Control the text color of an element to blue-600 using the
text-blue-600
utilities.
Conclusion
The above is a step-by-step tutorial on how to use Tailwind CSS to build a Progress Slider Component components, learn and follow along to implement your own components.