How to Make a Mac OSX-like Animated Folder with CSS3

Demo Download

In this short tutorial, we are going to make a OSX-like folder with CSS3, by utilizing 3D transforms, gradients and box shadows. In addition, we are going to use jQuery UI and its drag and drop interactions to build a pretty interactive demo.


The HTML of the folder is as simple as it gets - we only need a div for the front cover and one of the back:

<div class="folder">
    <div class="front"></div>
    <div class="back"></div>

In the great spirit of CSS3 traditions, we are keeping the needed markup to a minimum, and we are depending on the pseudo :before and :after elements to add the finer details. See the illustration below for an example.


And here is the page we will be working on. Inside #main div is the folder and the icons that we will be setting as draggables using jQuery UI:


<!DOCTYPE html>
        <meta charset="utf-8" />
        <title>How to Make a OSX-like Animated Folder with CSS3 | Tutorialzine </title>

        <!-- The jQuery UI Styles -->
        <link rel="stylesheet" href="" />

        <!-- Our stylesheet -->
        <link rel="stylesheet" href="assets/css/styles.css" />


        <div id="main">

            <div class="folder">
                <div class="front"></div>
                <div class="back"></div>

            <img src="assets/48px/box.png" style="top:340px;left:100px;" alt="box" />
            <!-- More icons here .. -->


        <!-- JavaScript Includes -->
        <script src=""></script>
        <script src=""></script>
        <script src="assets/js/script.js"></script>


Also, before the closing body tag I am including the jQuery library and jQuery UI, along with the script.js file that you will see later. First, let's discuss the most important part - the CSS.


To start, we will style the div with the folder class you saw above. This is also the place where we define the perspective setting, which is important for the 3D CSS effect. You can think of this property as your distance from the element (the closer you are, the more pronounced the perspective is).


.folder {
    /* This will enable the 3D effect. Decrease this value
     * to make the perspective more pronounced: */

    -webkit-perspective: 800px;
    -moz-perspective: 800px;
    perspective: 800px;

    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 0;

    width: 160px;
    height: 120px;
    margin: -100px 0 0 -60px;

After this, we will style the .front and .back divs that comprise the folder. I have grouped the rules that these elements have in common in the .folder div block:

.folder div{


    /* Enabling 3d space for the transforms */
    -webkit-transform-style: preserve-3d;
    -moz-transform-style: preserve-3d;
    transform-style: preserve-3d;

    /* Enabling a smooth animated transition */

    /* Disable text seleltion on the folder */
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;


I am using the transition property to tell the browser that it should animate between changes in the values of the other CSS properties. This will cause the folder to open smoothly when we start dragging one of the icons. Next is the front div:

.folder .front{
    border-radius:5px 5px 0 0;


    -moz-transform-origin:50% 100%;
    -webkit-transform-origin:50% 100%;
    transform-origin:50% 100%;

    background-image: -moz-linear-gradient(top, #93bad8 0%, #6c9dc0 85%, #628faf 100%);
    background-image: -webkit-linear-gradient(top, #93bad8 0%, #6c9dc0 85%, #628faf 100%);
    background-image: linear-gradient(top, #93bad8 0%, #6c9dc0 85%, #628faf 100%);

    box-shadow:0 -2px 2px rgba(0,0,0,0.1), 0 1px rgba(255,255,255,0.35) inset;


    font: bold 26px sans-serif;
    color: #5A88A9;
    text-align: center;
    text-shadow: 1px 1px 1px rgba(255, 255, 255, 0.1);
    line-height: 115px;

This is where we set the background of the front cover, and apply the initial rotation. This leaves the back cover:

.folder .back{
    background-image: -webkit-linear-gradient(top, #93bad8 0%, #89afcc 10%, #5985a5 60%);
    background-image: -moz-linear-gradient(top, #93bad8 0%, #89afcc 10%, #5985a5 60%);
    background-image: linear-gradient(top, #93bad8 0%, #89afcc 10%, #5985a5 60%);

    border-radius:0 5px 0 0;
    box-shadow:0 -1px 1px rgba(0,0,0,0.15);

/* The top part */
.folder .back:before{
    border-radius:4px 4px 0 0;
    box-shadow:0 -1px 1px rgba(0,0,0,0.15);

/* The shadow */
.folder .back:after{
    box-shadow:0 4px 8px #333;

All that is left, is to define the open class on the folder. When this class is added, the front will tilt forward as a result by the larger rotateX value. .front{

Great! Now let's sprinkle some jQuery goodness to make the example work:


As I mentioned previously, we are using jQuery UI and the drag&drop interaction to allow users to move icons around. When a drag starts, we will apply the open class to the folder which triggers the CSS3 transition.


$(function() {

    var folder = $("#main .folder"),
        front = folder.find('.front'),
        img = $("#main img"),
        droppedCount = 0;


        drop : function(event, ui) {

            // Remove the dragged icon

            // update the counters


        activate : function(){
            // When the user starts draggin an icon

        deactivate : function(){
            // Close the folder

And with this we're done!

Wrap up

It is cool that so much can be done with CSS3 without much effort. But it could be even cooler - you could use the HTML5 File APIs and allow users to upload files by dragging them from their desktops (hint: remember this tut?). I am sure that you folks will think of wonderful ways to enhance this code.

Presenting Bootstrap Studio

a revolutionary tool that developers and designers use to create
beautiful interfaces using the Bootstrap Framework.

Learn more
Web Browser Frame DevKit Box Mouse Cursor

Related Articles

This discussion is closed.
Aminul Islam

Owa! boss. Its awesome. Let me try :)

Thank you!

Simply state of the art UI :)

Great work! ...needs evolving so we can open the folder and retrieve whatever's in there though...if it could incorporate that it would be a killer pieve of work. Well done.

Kawasar Ali

Great tutorial. Very creative

very nice , tnx

Muhammed Athimannil

Awesome :)


Simply awesome, i will try this one.

I have been poking around a bit. In case anyone is interested;

Cool~just like in Mac OS

This is so cool! Interesting what can be done with CSS3...

I need to try this one, I am thinking countless ideas that I can do with this technique. Thanks for the tut!

Very nice!

Great !!

wow, this is amazing.

Alex Dimitrov

What i really love about this tutorial is that it shows technique used like 70% of the time - toggling classes for creating such awesome effects. This tutorial alone is enough for completing most of the day-to-day challenges when building web apps

Brilliant output