How to Build a Card component using Tailwind CSS ?
Last Updated :
26 Apr, 2025
In this article, we will learn about how to Build a card component using Tailwind CSS, Tailwind CSS is a CSS framework that helps in building rapid custom UI. It is a highly customizable, low-level CSS framework that gives you all of the building blocks that you need. Tailwind CSS creates small utilities with a defined set of options enabling easy integration of existing classes directly into the HTML code. In this article, we will see how to build the card component using the Tailwind CSS.
A Card Component is like a container used to group some related information. The card usually shows information in an appealing way and can be a blog post, a user profile, etc. We may use these card components to show our data and information to your users in multiple forms and contexts.
Syntax:
<div class="block p-6 max-w-sm bg-green-600
rounded-lg border border-gray-200">
<h1 class="mb-2 text-3xl font-bold text-gray-900>
...
</h1>
<p class=" font-normal text-white">
...
</p>
</div>
Tailwind CSS Classes: To create a card component, we have used some utility classes of tailwind CSS.
- block: It is used to create a block-level element by using the .block class.
- p-6: It is used to give the padding of 6 from all sides.
- max-w-sm: It is used to set the max width of the component as small.
- rounded-lg: It is used to set the rounded corners as large.
- border border-gray-200: It is used to add a border of a grey color.
- shadow-md: It is used to add shadows of medium size.
- mb-2: It adds the margin-bottom of 1 rem.
- text-3xl: It makes the font size 1.875rem.
- font-bold: It makes the font size bold.
- text-gray-900: It makes the text color gray.
- text-white: It makes the text color white.
Tailwind CSS Installation: There are 2 ways through which the Tailwind CSS can be used:
- Using the MPM installation
- Using the CDN link
We will understand both approaches for utilizing the Tailwind CSS. The following step will be followed for the Tailwind CSS Installation, is described below:
- Install the package available on npm using the following command:
npm install tailwindcss
- After that create an ad Tailwind configuration file using the following command:
npm tailwind init {name of file}
Using Tailwind CSS CDN Link:
- Add the CDN script tag to the <head> of the HTML file and start using Tailwind’s utility classes to style the content:
<script src="https://cdn.tailwindcss.com"></script>
- Adding Tailwind to your project:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>GeeksforGeeks</title>
<script src=
"https://cdn.tailwindcss.com"></script>
</head>
<body>
...
</body>
</html>
<div class="block p-6 max-w-sm
bg-green-600 rounded-lg
border border-grey-200 shadow-md">
...
</div>
- Add Headers and main content:
<h1 class="mb-2 text-3xl font-bold text-gray-900">
Header
</h1>
<p class="text-white">
content goes here...
</p>
Example 1: Below example demonstrates the basic card component created using Tailwind CSS.
HTML
<!DOCTYPE html>
< html lang = "en" >
< head >
< meta charset = "utf-8" />
< title >Card Component In Tailwind CSS</ title >
< script src =
</ script >
</ head >
< body >
< div style = "text-align: center" >
< h1 class="text-green-600
text-3xl font-bold">
GeeksforGeeks
</ h1 >
< h3 class = "text-xl" >
Card in Tailwind CSS
</ h3 >
</ div >
< div class = "py-4 flex justify-center" >
< div class="block p-6 max-w-sm
bg-green-600
rounded-lg border
border-gray-200 shadow-md">
< h1 class="mb-2 text-3xl
font-bold
text-gray-900
dark:text-white">
GeeksforGeeks
</ h1 >
< p class = "font-normal text-white" >
GeeksforGeeks aka GFG is an online platform
that provides Free Tutorials, Millions of
Articles, Live, Online and Classroom Courses,
Frequent Coding Competitions ,Webinars by
Industry Experts, Internship opportunities
and Job Opportunities.
</ p >
</ div >
</ div >
</ body >
</ html >
|
Output:
Example 2: Below example demonstrates the card component with the image using Tailwind CSS.
HTML
<!DOCTYPE html>
< html lang = "en" >
< head >
< meta charset = "utf-8" />
< title >GeeksforGeeks</ title >
< script src =
</ script >
</ head >
< body >
< div style = "text-align: center" >
< h1 class="text-green-600
text-3xl font-bold">
GeeksforGeeks
</ h1 >
< h3 class = "text-xl" >
Card in Tailwind CSS
</ h3 >
</ div >
< div class="py-4
flex justify-center">
< div class="w-full
max-w-sm
bg-gray-800
rounded-lg
border border-gray-200
shadow-md">
< div class="flex flex-col
items-center pt-4 pb-10">
< img class="mb-3 w-24 h-24
rounded-full shadow-lg"
src =
alt = "gfg" />
< h5 class="mb-1 text-xl
font-medium
text-gray-900
dark:text-white">
GeeksforGeeks
</ h5 >
< span class="text-sm
text-gray-500
dark:text-gray-400">
Coding Platform
</ span >
< div class = "flex mt-4 space-x-3 md:mt-6" >
class="inline-flex items-center py-2 px-4
text-sm font-medium text-center
text-white bg-green-600 rounded-lg
hover:bg-green-700 focus:ring-4
focus:outline-none focus:ring-blue-300">
Website
</ a >
< a href = "#"
class="inline-flex items-center py-2 px-4
text-sm font-medium text-center
text-gray-900 bg-white rounded-lg
border border-gray-300 hover:bg-gray-100
focus:ring-4 focus:outline-none
focus:ring-gray-200 dark:bg-gray-800
dark:text-white dark:border-gray-600
dark:hover:bg-gray-700
dark:hover:border-gray-700
dark:focus:ring-gray-700">
Contact
</ a >
</ div >
</ div >
</ div >
</ div >
</ body >
</ html >
|
Output:

Similar Reads
How To Add Badge Components Using Tailwind CSS?
Badges are versatile UI components that display notifications, counts, or statuses. Web applications use them extensively to enhance user experience by providing visual cues. Whether you are creating a social media platform, a notification system, or an e-commerce application, badges help improve in
3 min read
How to create a Chevron using Tailwind CSS ?
A Chevron is a basic geometric shape that is used in websites to indicate directional movements or navigation. By utilizing specific border properties and transformations, a chevron shape can be achieved without the need for custom CSS. Tailwind's utility-first approach allows for a straightforward
3 min read
How to Center an Image using Tailwind CSS ?
Here are the methods to center an image using Tailwind CSS: Method 1. Using Flexbox ClassesThis method centers the image both horizontally and vertically using Tailwind's flex, justify-center, and items-center classes. [GFGTABS] HTML <html> <head> <script src="https://cdn.tailwin
3 min read
How to create Calculator Card using Tailwind CSS & JavaScript ?
In this article, we'll create a Basic Calculator using the Tailwind CSS and JavaScript. The application allows users to input any numerical data and give the calculated result. We'll utilize Tailwind CSS for styling to create an attractive user interface and JavaScript for the logic. Approach to cre
3 min read
How to centre an Element using Tailwind CSS ?
Tailwind CSS follows a utility-first approach, which means that instead of writing custom CSS for each component, we can utilize pre-defined classes that apply specific styles directly to HTML elements. We can center an element by using the utility classes of "margin" and "flex". This article will g
3 min read
Create Contact Cards Component Using Next.js and Tailwind CSS
The contact card component can display user information, such as a profile picture, contact details, and links to social media profiles. We will use Tailwind CSS for styling to ensure the card is visually appealing and responsive. Output Preview: Let us have a look at how the final output will look
4 min read
How to create NPV Calculator Card using JavaScript & Tailwind CSS ?
A Net Present Value (NPV) Calculator is a web-based tool that helps users calculate the net present value of an investment. It typically includes input fields for the initial investment amount, the discount rate, and the expected cash flows. The calculator then calculates the NPV based on these inpu
3 min read
Create Progress Bar Component using React and Tailwind CSS
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. PrerequisitesJavaScriptReactTa
2 min read
How to create GPA Calculator Card using JavaScript and Tailwind CSS ?
A GPA (Grade Point Average) Calculator using Tailwind CSS, and JavaScript allows users to input the credits and select the grade for each course, and it will calculate the GPA based on these inputs. Output Preview: Let us have a look at how the final output will look like. Approach to create GPA Cal
4 min read
Onsen UI CSS Component Basic Card
Onsen UI CSS is used to create beautiful HTML components. It is one of the most efficient ways to create HTML5 hybrid components that are compatible with both mobile and desktop. In this article, we are going to implement the Onsen UI CSS Component Basic Card component. A card is an HTML component u
2 min read