- Published on
6 Easy Ways To Make A Pretty Accordion With Decent Animation With Tailwind CSS Without Even Thinking About It

- What is Tailwind CSS?
- The description of Pretty accordion with decent animation ui component
- Why use Tailwind CSS to build a Pretty accordion with decent animation ui component?
- The preview of Pretty accordion with decent animation ui component
- The source code of Pretty accordion with decent animation ui component
- How to build a Pretty accordion with decent animation with Tailwind CSS?
- Install tailwind css of verion 2.2.4
- All the unility class needed to build a Pretty accordion with decent animation component
- 25 steps to build a Pretty accordion with decent animation 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 Pretty accordion with decent animation ui component
Simple and pretty accordion with decent animation
Why use Tailwind CSS to build a Pretty accordion with decent animation ui component?
- It can make the building process of Pretty accordion with decent animation ui component faster and more easily.
- Enables building complex responsive layouts and components freely.
- Minimum lines of CSS code in Pretty accordion with decent animation component file.
The preview of Pretty accordion with decent animation ui component
Free download of the Pretty accordion with decent animation's source code
The source code of Pretty accordion with decent animation ui component
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Accordion | TailwindCSS x AlpineJS </title>
<link href="https://unpkg.com/[email protected]^2/dist/tailwind.min.css" rel="stylesheet" />
<!-- <link rel="stylesheet" href="./assets/styles/styles.css" /> -->
<script defer src="https://unpkg.com/[email protected]/dist/cdn.min.js"></script>
</head>
<body class="h-screen bg-blue-50">
<main class="p-5 bg-light-blue">
<div class="flex justify-center items-start my-2">
<div class="w-full sm:w-10/12 md:w-1/2 my-1">
<h2 class="text-xl font-semibold text-vnet-blue mb-2">FAQ - Order, Shipping, Etc.</h2>
<ul class="flex flex-col">
<li class="bg-white my-2 shadow-lg" x-data="accordion(1)">
<h2
@click="handleClick()"
class="flex flex-row justify-between items-center font-semibold p-3 cursor-pointer"
>
<span>When will my order arrive?</span>
<svg
:class="handleRotate()"
class="fill-current text-purple-700 h-6 w-6 transform transition-transform duration-500"
viewBox="0 0 20 20"
>
<path d="M13.962,8.885l-3.736,3.739c-0.086,0.086-0.201,0.13-0.314,0.13S9.686,12.71,9.6,12.624l-3.562-3.56C5.863,8.892,5.863,8.611,6.036,8.438c0.175-0.173,0.454-0.173,0.626,0l3.25,3.247l3.426-3.424c0.173-0.172,0.451-0.172,0.624,0C14.137,8.434,14.137,8.712,13.962,8.885 M18.406,10c0,4.644-3.763,8.406-8.406,8.406S1.594,14.644,1.594,10S5.356,1.594,10,1.594S18.406,5.356,18.406,10 M17.521,10c0-4.148-3.373-7.521-7.521-7.521c-4.148,0-7.521,3.374-7.521,7.521c0,4.147,3.374,7.521,7.521,7.521C14.148,17.521,17.521,14.147,17.521,10"></path>
</svg>
</h2>
<div
x-ref="tab"
:style="handleToggle()"
class="border-l-2 border-purple-600 overflow-hidden max-h-0 duration-500 transition-all"
>
<p class="p-3 text-gray-900">
Shipping time is set by our delivery partners, according to the delivery method chosen by you. Additional details can be found in the order confirmation
</p>
</div>
</li>
<li class="bg-white my-2 shadow-lg" x-data="accordion(2)">
<h2
@click="handleClick()"
class="flex flex-row justify-between items-center font-semibold p-3 cursor-pointer"
>
<span>How do I track my order?</span>
<svg
:class="handleRotate()"
class="fill-current text-purple-700 h-6 w-6 transform transition-transform duration-500"
viewBox="0 0 20 20"
>
<path d="M13.962,8.885l-3.736,3.739c-0.086,0.086-0.201,0.13-0.314,0.13S9.686,12.71,9.6,12.624l-3.562-3.56C5.863,8.892,5.863,8.611,6.036,8.438c0.175-0.173,0.454-0.173,0.626,0l3.25,3.247l3.426-3.424c0.173-0.172,0.451-0.172,0.624,0C14.137,8.434,14.137,8.712,13.962,8.885 M18.406,10c0,4.644-3.763,8.406-8.406,8.406S1.594,14.644,1.594,10S5.356,1.594,10,1.594S18.406,5.356,18.406,10 M17.521,10c0-4.148-3.373-7.521-7.521-7.521c-4.148,0-7.521,3.374-7.521,7.521c0,4.147,3.374,7.521,7.521,7.521C14.148,17.521,17.521,14.147,17.521,10"></path>
</svg>
</h2>
<div
class="border-l-2 border-purple-600 overflow-hidden max-h-0 duration-500 transition-all"
x-ref="tab"
:style="handleToggle()"
>
<p class="p-3 text-gray-900">
Once shipped, you’ll get a confirmation email that includes a tracking number and additional information regarding tracking your order.
</p>
</div>
</li>
<li class="bg-white my-2 shadow-lg" x-data="accordion(3)">
<h2
@click="handleClick()"
class="flex flex-row justify-between items-center font-semibold p-3 cursor-pointer"
>
<span>What’s your return policy?</span>
<svg
:class="handleRotate()"
class="fill-current text-purple-700 h-6 w-6 transform transition-transform duration-500"
viewBox="0 0 20 20"
>
<path d="M13.962,8.885l-3.736,3.739c-0.086,0.086-0.201,0.13-0.314,0.13S9.686,12.71,9.6,12.624l-3.562-3.56C5.863,8.892,5.863,8.611,6.036,8.438c0.175-0.173,0.454-0.173,0.626,0l3.25,3.247l3.426-3.424c0.173-0.172,0.451-0.172,0.624,0C14.137,8.434,14.137,8.712,13.962,8.885 M18.406,10c0,4.644-3.763,8.406-8.406,8.406S1.594,14.644,1.594,10S5.356,1.594,10,1.594S18.406,5.356,18.406,10 M17.521,10c0-4.148-3.373-7.521-7.521-7.521c-4.148,0-7.521,3.374-7.521,7.521c0,4.147,3.374,7.521,7.521,7.521C14.148,17.521,17.521,14.147,17.521,10"></path>
</svg>
</h2>
<div
class="border-l-2 border-purple-600 overflow-hidden max-h-0 duration-500 transition-all"
x-ref="tab"
:style="handleToggle()"
>
<p class="p-3 text-gray-900">
We allow the return of all items within 30 days of your original order’s date. If you’re interested in returning your items, send us an email with your order number and we’ll ship a return label.
</p>
</div>
</li>
<li class="bg-white my-2 shadow-lg" x-data="accordion(4)">
<h2
@click="handleClick()"
class="flex flex-row justify-between items-center font-semibold p-3 cursor-pointer"
>
<span>How do I make changes to an existing order?</span>
<svg
:class="handleRotate()"
class="fill-current text-purple-700 h-6 w-6 transform transition-transform duration-500"
viewBox="0 0 20 20"
>
<path d="M13.962,8.885l-3.736,3.739c-0.086,0.086-0.201,0.13-0.314,0.13S9.686,12.71,9.6,12.624l-3.562-3.56C5.863,8.892,5.863,8.611,6.036,8.438c0.175-0.173,0.454-0.173,0.626,0l3.25,3.247l3.426-3.424c0.173-0.172,0.451-0.172,0.624,0C14.137,8.434,14.137,8.712,13.962,8.885 M18.406,10c0,4.644-3.763,8.406-8.406,8.406S1.594,14.644,1.594,10S5.356,1.594,10,1.594S18.406,5.356,18.406,10 M17.521,10c0-4.148-3.373-7.521-7.521-7.521c-4.148,0-7.521,3.374-7.521,7.521c0,4.147,3.374,7.521,7.521,7.521C14.148,17.521,17.521,14.147,17.521,10"></path>
</svg>
</h2>
<div
class="border-l-2 border-purple-600 overflow-hidden max-h-0 duration-500 transition-all"
x-ref="tab"
:style="handleToggle()"
>
<p class="p-3 text-gray-900">
Changes to an existing order can be made as long as the order is still in “processing” status. Please contact our team via email and we’ll make sure to apply the needed changes. If your order has already been shipped, we cannot apply any changes to it. If you are unhappy with your order when it arrives, please contact us for any changes you may require.
</p>
</div>
</li>
<li class="bg-white my-2 shadow-lg" x-data="accordion(5)">
<h2
@click="handleClick()"
class="flex flex-row justify-between items-center font-semibold p-3 cursor-pointer"
>
<span>What shipping options do you have?</span>
<svg
:class="handleRotate()"
class="fill-current text-purple-700 h-6 w-6 transform transition-transform duration-500"
viewBox="0 0 20 20"
>
<path d="M13.962,8.885l-3.736,3.739c-0.086,0.086-0.201,0.13-0.314,0.13S9.686,12.71,9.6,12.624l-3.562-3.56C5.863,8.892,5.863,8.611,6.036,8.438c0.175-0.173,0.454-0.173,0.626,0l3.25,3.247l3.426-3.424c0.173-0.172,0.451-0.172,0.624,0C14.137,8.434,14.137,8.712,13.962,8.885 M18.406,10c0,4.644-3.763,8.406-8.406,8.406S1.594,14.644,1.594,10S5.356,1.594,10,1.594S18.406,5.356,18.406,10 M17.521,10c0-4.148-3.373-7.521-7.521-7.521c-4.148,0-7.521,3.374-7.521,7.521c0,4.147,3.374,7.521,7.521,7.521C14.148,17.521,17.521,14.147,17.521,10"></path>
</svg>
</h2>
<div
class="border-l-2 border-purple-600 overflow-hidden max-h-0 duration-500 transition-all"
x-ref="tab"
:style="handleToggle()"
>
<p class="p-3 text-gray-900">
For USA domestic orders we offer FedEx and USPS shipping.
</p>
</div>
</li>
<li class="bg-white my-2 shadow-lg" x-data="accordion(6)">
<h2
@click="handleClick()"
class="flex flex-row justify-between items-center font-semibold p-3 cursor-pointer"
>
<span>What payment methods do you accept?</span>
<svg
:class="handleRotate()"
class="fill-current text-purple-700 h-6 w-6 transform transition-transform duration-500"
viewBox="0 0 20 20"
>
<path d="M13.962,8.885l-3.736,3.739c-0.086,0.086-0.201,0.13-0.314,0.13S9.686,12.71,9.6,12.624l-3.562-3.56C5.863,8.892,5.863,8.611,6.036,8.438c0.175-0.173,0.454-0.173,0.626,0l3.25,3.247l3.426-3.424c0.173-0.172,0.451-0.172,0.624,0C14.137,8.434,14.137,8.712,13.962,8.885 M18.406,10c0,4.644-3.763,8.406-8.406,8.406S1.594,14.644,1.594,10S5.356,1.594,10,1.594S18.406,5.356,18.406,10 M17.521,10c0-4.148-3.373-7.521-7.521-7.521c-4.148,0-7.521,3.374-7.521,7.521c0,4.147,3.374,7.521,7.521,7.521C14.148,17.521,17.521,14.147,17.521,10"></path>
</svg>
</h2>
<div
class="border-l-2 border-purple-600 overflow-hidden max-h-0 duration-500 transition-all"
x-ref="tab"
:style="handleToggle()"
>
<p class="p-3 text-gray-900">
Any method of payments acceptable by you. For example: We accept MasterCard, Visa, American Express, PayPal, JCB Discover, Gift Cards, etc.
</p>
</div>
</li>
</ul>
</div>
</div>
</main>
</body>
<script>
document.addEventListener('alpine:init', () => {
Alpine.store('accordion', {
tab: 0
});
Alpine.data('accordion', (idx) => ({
init() {
this.idx = idx;
},
idx: -1,
handleClick() {
this.$store.accordion.tab = this.$store.accordion.tab === this.idx ? 0 : this.idx;
},
handleRotate() {
return this.$store.accordion.tab === this.idx ? 'rotate-180' : '';
},
handleToggle() {
return this.$store.accordion.tab === this.idx ? `max-height: ${this.$refs.tab.scrollHeight}px` : '';
}
}));
})
</script>
</html>
How to build a Pretty accordion with decent animation with Tailwind CSS?
Install tailwind css of verion 2.2.4
Use the script
html tag to import the script of Tailwind CSS of the version 2.2.4
<script src="https://cdn.tailwindcss.com"></script>
All the unility class needed to build a Pretty accordion with decent animation component
h-screen
bg-blue-50
p-5
bg-light-blue
flex
my-2
w-full
sm:w-10/12
md:w-1/2
my-1
text-xl
text-vnet-blue
mb-2
flex-col
bg-white
flex-row
p-3
text-purple-700
h-6
w-6
border-l-2
border-purple-600
overflow-hidden
max-h-0
text-gray-900
25 steps to build a Pretty accordion with decent animation component with Tailwind CSS
Use
h-screen
to make an element span the entire height of the viewport.Control the background color of an element to blue-50 using the
bg-blue-50
utilities.Control the padding on all sides of an element to 1.25rem using the
p-5
utilities.Control the background color of an element to light-blue using the
bg-light-blue
utilities.Use
flex
to create a block-level flex container.Control the vertical margin of an element to 0.5rem using the
my-2
utilities.Use
w-full
to set an element to a 100% based width.Use
sm:w-10/12
to set an element to a fixed width(10/12) at only small screen sizes.Use
md:w-1/2
to set an element to a fixed width(1/2) at only medium screen sizes.Control the vertical margin of an element to 0.25rem using the
my-1
utilities.Control the text color of an element to xl using the
text-xl
utilities.Control the text color of an element to vnet-blue using the
text-vnet-blue
utilities.Control the margin on bottom side of an element to 0.5rem using the
mb-2
utilities.Use
flex
to create a block-level flex container.Control the background color of an element to white using the
bg-white
utilities.Use
flex
to create a block-level flex container.Control the padding on all sides of an element to 0.75rem using the
p-3
utilities.Control the text color of an element to purple-700 using the
text-purple-700
utilities.Use
h-6
to set an element to a fixed height(1.5rem).Use
w-6
to set an element to a fixed width(1.5rem).Control the border color of an element to l-2 using the
border-l-2
utilities.Control the border color of an element to purple-600 using the
border-purple-600
utilities.Use
overflow-hidden
to clip any content within an element that overflows the bounds of that element.Set the maximum width/height of an element using the
max-h-0
utilities.Control the text color of an element to gray-900 using the
text-gray-900
utilities.
Conclusion
The above is a step-by-step tutorial on how to use Tailwind CSS to build a Pretty accordion with decent animation components, learn and follow along to implement your own components.