Create Testimonials Using React and Tailwind CSS
Last Updated :
30 Sep, 2024
Customer testimonials are important in modern websites, particularly for businesses that rely on social proof to attract new customers. Displaying authentic customer feedback in an aesthetically pleasing manner can boost credibility and trust.
In this article, we’ll create a Testimonials Section using React and Tailwind CSS and React Icons for added visual appeal.
Prerequisites
Approaches for Creating Testimonial
- Initialize a new React project using Create React App and tailwind CSS and configure it for the project.
- Set the content paths in the Tailwind configuration file to ensure it processes the relevant files.
- Import Tailwind's base styles into the main CSS file of your project.
- Define a reusable Testimonial component that will accept props such as the testimonial text, author name, and image.
- Ensure the component is styled using Tailwind CSS classes for a clean and modern look.
- In the main application component, create a list of testimonial data (like names, texts, and images).
- Map through the testimonial data to render the Testimonial component for each entry.
Steps To Create Testimonials
Step 1: Set up a React Application
npx create-react-app react-app
cd react-app
Step 2: Install Tailwind CSS using the command.
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
Step 3: Configure the tailwind paths in your tailwind.config.js file.
module.exports = {
content: ["./src/**/*.{js,jsx,ts,tsx}"],
theme: {
extend: {
colors: {
primaryGreen: "#4CAF50", // Green
primaryBlack: "#000000", // Black
primaryWhite: "#FFFFFF", // White
}
},
},
plugins: [],
}
Step 4: Add tailwind directives to your index.css file.
@tailwind base;
@tailwind components;
@tailwind utilities;
body {
margin: 0;
font-family: 'Times New Roman', Times, serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
h2 {
margin-top: 2rem;
/* Adjust top margin for spacing */
}
Project Structure
Project StructureUpdated dependencies:
"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-icons": "^5.3.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
}
Example: This demonstrates the creation of Testimonials using React and Tailwind CSS:
JavaScript
// Testimonial.js
import React from 'react';
import { FaStar, FaQuoteLeft } from 'react-icons/fa';
const testimonials = [
{
id: 1,
name: "Jane Doe",
image: "https://via.placeholder.com/150",
review: "This product exceeded my expectations! I would
definitely recommend it to others.",
rating: 5,
},
{
id: 2,
name: "John Smith",
image: "https://via.placeholder.com/150",
review: "Great quality and fast shipping. The customer service
was also very helpful.",
rating: 4,
},
{
id: 3,
name: "Sara Lee",
image: "https://via.placeholder.com/150",
review: "I love the design and the functionality of this product.
It's perfect for my needs.",
rating: 5,
},
{
id: 4,
name: "Michael Johnson",
image: "https://via.placeholder.com/150",
review: "Affordable and reliable. I've been using it for a while
now and it hasn't disappointed.",
rating: 4,
},
{
id: 5,
name: "Emily Watson",
image: "https://via.placeholder.com/150",
review: "The best product in its category. I can't imagine going
back to anything else.",
rating: 5,
},
{
id: 6,
name: "David Lee",
image: "https://via.placeholder.com/150",
review: "Solid performance and great value for money. Highly recommended!",
rating: 5,
}
];
const Testimonial = () => {
const handleCardClick = (id) => {
console.log(`Card with ID ${id} clicked!`);
// You can also navigate to a detailed page or perform any action here
};
return (
<div className="flex flex-col items-center p-6 bg-green-500 min-h-screen">
<h1 className="text-3xl font-bold text-white mb-8">Testimonials</h1>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8
max-w-6xl">
{testimonials.map(({ id, name, image, review, rating }) => (
<div
key={id}
className="bg-white rounded-lg p-6 shadow-lg transform
transition-transform duration-200 hover:scale-105 cursor-pointer"
onClick={() => handleCardClick(id)} // Make the card clickable
>
<div className="flex items-center mb-4">
<img className="w-16 h-16 rounded-full mr-4" src={image}
alt={name} />
<div>
<h2 className="font-semibold text-lg">{name}</h2>
<div className="flex text-yellow-500">
{[...Array(rating)].map((_, i) => (
<FaStar key={i} />
))}
</div>
</div>
</div>
<p className="text-gray-600 italic">
<FaQuoteLeft className="inline mr-2 text-gray-400" />
{review}
</p>
</div>
))}
</div>
</div>
);
};
export default Testimonial;
JavaScript
// App.js
import React from 'react';
import Testimonial from './Testimonial';
const App = () => {
return (
<div className="App">
<Testimonial />
</div>
);
};
export default App;
Step 5: Run the Application
Once Development is completed Now we need run the react js application by using below command. By default the react js application run on port number 3000.
npm start
Output:
Similar Reads
Create Team Sections Using React and Tailwind CSS In this article, we will create a Team Section using React and Tailwind CSS. The team section will display team member information including their name role, and profile picture with a responsive and modern layout. Tailwind CSS simplifies styling by using utility first classes making the development
3 min read
Create Podcast Template using React and Tailwind CSS Podcasts have become a popular medium for sharing knowledge and entertainment. Creating a podcast application can be a fun project that not only enhances your skills in React and Tailwind CSS but also provides a platform to showcase your favourite podcasts. In this template we will build a responsiv
6 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 Feeds UI using React and Tailwind CSS In the world of social networking, feeds are the primary way users interact with content. Whether it is on LinkedIn, Facebook, or Twitter the feed showcases posts updates, and activities from people or organizations. This article will help you build a LinkedIn-style feed UI using React and Tailwind
4 min read
Create Navbars UI using React and Tailwind CSS A UI plays an important role because a clean, well-designed interface creates a positive first impression and if the UI is good then users can stay on our website some more time and if the UI is bad then they can not stay on our site for more time. we will see how to Create Navbars UI using React an
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