The flipping card animation can not only provide functionality and ease of use to any webpage, but can also make your site feel more refined, user-friendly and, most importantly, modern and trustworthy.
The animation is a perfect example of bringing real-world movement and functions to the web, and improving usability through that.
A few ideas for use cases for the flipping card animation include:
- Flashcards, or anything that reveals something else — the flipping card animation is great for revealing any sort of hidden information, especially when that piece of hidden information is directly connected to an opposite piece of "public" information. A prime example of this is flashcards, for example word-definition flashcards on sites like Quizlet. A more literal example could be that of a playing card, with a typical back of the card, and a front side with its face, number and suit.
- Sign-In and Sign-Up forms — the flipping card animation can be great for things that have two options. One great example of this is the sign-in and sign-up forms on a site. Normally, these are on two different pages, but one idea to consider could be to have both forms be on one page, with each form being on one single flipping card (one form on the back, the other on the front), and that card can be flipped with CSS if the user wants to sign-in or sign-up respectively.
Let's Write the CSS!
Luckily, with new, modern CSS properties and styles, we can build this animation and functionality pretty quickly, with very little code, yet make it look extremely professional and new.
If you would like, check out the finished CodePen.
First, we will write the basic HTML and CSS of the card. The card will have a container, which is what we will be flipping with CSS, and that container will have two children: a front side element and a back side element. Both children and the container are sized in the CSS with the exact same height and width, which is imperative for this to work. Apart from that, all the other styles below are just for the example and are completely changeable for your own circumstances.
This gives us a result that is something like this, which is effectively everything but the actual flipping card animation:
Now that we have the basic styles, we will build the actual animation.
The first step is to position both sides as absolute at the top left of the container (which we will set as relative). We will also set the "backface visibility" to hidden, which means that users cannot see the back side of the flipping card when the front is showing. Then comes the key to the animation, which is the "transform: rotateY" property, in which we will transition into onboth sides. The back side will be initially rotated across the y-axis 180 degrees to the back, and will therefore be hidden by the backface visibility property. When we flip the card (on-hover in this case, but you can change this to something else of course), the back side will rotated 0 degrees to the front, and the front side will be rotated 180 degrees to the back. All of this is again transitioned into with CSS to make that really cool animation we're looking to build. You can of course change the transition time or timing function for your needs, but other styles should be kept the same to ensure the perfect animation functionality.
With this, we are almost done, but there is one last thing we have to add to make everything look really smooth, and that is the CSS perspective property. The perspective property makes our transition look 3D. We add this property to the parent element, which in this case is the container. The value of the property does affect how it turns out, so feel free to play around with it!
If you'd like, check out the finished CodePen.
Of course, it does have some limitations, particularly on mobile with hover effects and graphics, and of course some of these new CSS properties may not be supported on older browsers such as IE or less-used ones like the KaiOS Browser.
I hope you enjoyed this post, and all of the code written is CC0 Licensed, meaning you can use it without attribution of any kind.
Share this post (on the right) if you liked it, and thanks for scrolling.
— Gabriel Romualdo, 26 November, 2019<!--Give this post a ❤️ if you liked it, and thanks for scrolling. **Originally published on my personal website: [xtrp.io](https://xtrp.io/)**-->