Create Progress Bar Component using React and Tailwind CSS
Last Updated :
01 Oct, 2024
A progress bar is a visual representation of progress in a process. It is commonly used in web applications to indicate the completion status of an operation. In this article, we will learn how to create a progress bar component in React using Tailwind CSS for styling.
Prerequisites
Approach
- Ensure you have a React project set up and Tailwind CSS installed. You can create a new React app using Create React App and add Tailwind CSS.
- Create a new component called
ProgressBar
. This component will accept props for the progress percentage and any additional customization you might want (like colors). - Use Tailwind CSS classes to style the progress bar. This includes setting the background, height, and animations.
Steps to Create Progress Bar Component
Step 1: Set up the React project using the command
npx create-react-app progress-bar-app
Step 2: Navigate to the path of the directory and install Tailwind CSS using the command
cd progress-bar-app
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
Step 3: Configure the Tailwind paths in your tailwind.config.js file
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./src/**/*.{js,jsx,ts,tsx}",
],
theme: {
extend: {},
},
plugins: [],
}
Step 4: Add Tailwind directives to your index.css file
@tailwind base;
@tailwind components;
@tailwind utilities;
Project Structure:
Project Structure
Updated Dependencies:
{
"name": "progress-bar-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
}
Example: Below is a code example demonstrating the progress bar component, which updates its value based on user interaction. This component uses Tailwind CSS for styling.
JavaScript
// src/App.js
import React, { useState } from "react";
const App = () => {
const [progress, setProgress] = useState(0);
const increaseProgress = () => {
setProgress((prev) => Math.min(prev + 10, 100));
// Increase progress by 10%
};
return (
<div className="flex flex-col items-center justify-center h-screen bg-gray-100">
<h1 className="text-2xl font-bold mb-4">Progress Bar</h1>
<div className="relative w-full max-w-md h-6 bg-gray-300
rounded-full overflow-hidden">
<div
className="absolute h-full bg-blue-600 transition-all duration-300"
style={{ width: `${progress}%` }}
></div>
</div>
<p className="mt-2 text-lg font-semibold">{progress}%</p>
<button
onClick={increaseProgress}
className="mt-4 bg-blue-500 text-white py-2 px-4 rounded-lg
hover:bg-blue-600 transition-colors"
>
Increase Progress
</button>
</div>
);
};
export default App;
To start the Application, run the following command:
npm start
Output:
Similar Reads
Create Drawer Component using React and Tailwind CSS A drawer component is a sliding panel that comes from the side of the screen, often used for navigation menus or displaying additional content. In this article, we will learn how to create a responsive drawer component in React using Tailwind CSS for styling.PrerequisitesJavaScriptReactTailwind CSSA
3 min read
Create Description List Component Using React and Tailwind CSS A description list is an elementary method to show key-value pairs, where a term and its definition are presented side by side. In this article, we will see the way of styling and implementing it as a component in a React Project using Tailwind CSS.Prerequisites Node.jsReactTailwind CSSApproach to C
4 min read
Create Banners using React and Tailwind CSS We will build a responsive banner component using React and Tailwind CSS. Tailwind CSS allows us to create highly customizable and modern UI components with minimal effort. The banner will include a heading and subheading and a call to action button styled for responsiveness and accessibility.Prereq
3 min read
Create Content Sections using React and Tailwind CSS Creating well-structured content sections is crucial for any modern web application. In this article, we will walk through how to build content sections using React styled with Tailwind CSS and enhanced with React Icons. We will create a React application with multiple content sections. Each section
3 min read
Create Command Palettes UI using React and Tailwind CSS This article shows you how to create a Command Palette UI using React and Tailwind CSS. A command palette lets users easily search for and run commands within an app, making navigation faster and more efficient. Weâll walk you through building a simple and intuitive interface where users can type, s
4 min read
Create Logo Clouds using React and Tailwind CSS A Logo Cloud is a webpage section that displays logos of partners, sponsors, clients, or technologies in a visually appealing way. This component is often used to establish credibility or showcase affiliations. Using React and Tailwind CSS you can create a responsive and customizable logo cloud that
3 min read
Create Category Previews Using React And Tailwind CSS In modern web development creating visually appealing and functional components is essential for enhancing user experience. The goal is to showcase categories with distinct icons and a stylish green background using Tailwinds utility classes for a streamlined and responsive design.This article focus
4 min read
Create Footers Using React And Tailwind CSS We will learn how to create a responsive footer using React and Tailwind CSS with a modern design. The footer will feature a green background with white text providing a clean and professional look. We will create three sections: Contacts social media and Services to display important information an
3 min read
Create FAQs using React and Tailwind CSS A Frequently Asked Questions section is a common feature found on websites and applications that helps users find answers to common queries in an organized manner. A well-designed FAQ can improve user experience reduce support requests and provide users with quick and easy access to helpful informat
5 min read
Create Buttons UI using React and Tailwind CSS Tailwind CSS is a utility-first CSS framework that allows developers to quickly build responsive and reusable components. We'll explore how to create buttons with different styles such as primary, secondary, and disabled states, and buttons of various sizes.PrerequisitesReact JavaScriptNodeJSTailwin
2 min read