Animated Card Fan Effect with CSS | Interactive UI Design for Beginners
Creating interactive and animated layouts can dramatically improve how users engage with your website. In this tutorial, we’ll explore how to build a card fan animation effect using only HTML and CSS — no JavaScript required.
This effect creates a visual spread of cards when a user hovers over the container, and each card responds individually to mouse hover for extra interactivity.
What This Code Does
The project is built around four colored cards layered on top of each other. When the user hovers over the .main container, the cards spread apart like a fan, each rotating and shifting horizontally. On hovering over an individual card, that specific card rotates back to face forward, offering a crisp and clean spotlight effect.
How the Animation Works
1. Card Structure and Positioning
Each .card is absolutely positioned inside a .main container. This means all cards stack on top of one another until interacted with.
.cardelements have fixed size and a soft box shadow.Cards have unique background colors (
black,blue,red,green) to distinguish them.
2. Hovering on Container
When the user hovers over the .main element:
The cards shift left or right using
translateX().They also rotate to simulate a fan-like spread using
rotate().
3. Hovering on Individual Cards
Each card also has its own :hover state that:
Cancels the initial rotation using
rotate(0deg).Pulls the card out further, creating a focus effect.
Uses
!importantto override the container hover styles.
This gives each card a chance to stand out when the user moves their mouse over it, enhancing interactivity.
Why This Effect Is Useful
This fan animation is ideal for:
Showcasing product cards on e-commerce sites
Presenting portfolio items creatively
Interactive UI sections that require engagement
It’s lightweight, responsive, and perfect for users who are learning how to animate with CSS transitions and transforms.
Learn and Customize with “Learn Code Online Free Of Cost”
If you’re using the Learn Code Online Free Of Cost platform, you can:
Try this code live
Modify card count, colors, or animation angles
Understand how CSS transitions, transforms, and hover effects work together
This hands-on experience is perfect for beginners looking to boost their frontend skills.
Final Thoughts
The Card Fan Hover Animation demonstrates how small touches of CSS can create impressive visual effects without writing a single line of JavaScript. It’s a great example of how to work with positioning, transitions, and interactivity — all key skills for modern web developers.
This code uses HTML and CSS only — no JavaScript included.
Copyright – 2025 Sharkotech
Permission is freely granted to anyone who obtains a copy of this software and its accompanying documentation files (referred to as “the Software”), allowing them to use, copy, modify, merge, publish, distribute, sublicense, and even sell copies of the Software. Additionally, users are allowed to permit others to use the Software under these same terms.
It is required that the above copyright notices and this permission notice be included in all versions or significant portions of the Software.
Please note, the Software is provided “as is”, without any form of warranty—express or implied. This includes, but is not limited to, warranties of merchantability, fitness for a specific purpose, or non-infringement. Under no circumstances shall the original authors or rights holders be held responsible for any claims, damages, or other liabilities that may arise from the use of the Software, whether through legal action, negligence, or otherwise.
All code on Freeofcosts.com is reviewed before publishing. Each post includes a live code editor with real-time preview, so you can experiment and learn by doing. Most code is open-source and free to use or modify under respective licenses.



