CodeBlanks Logo Icon CodeBlanks

Animation Cube

A 3D cube built from six HTML panels that rotates continuously on two axes using CSS transforms and perspective.

View Source Fullscreen
HTML
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>3D Dönen Küp</title>
    </head>
    <body>
        <div id="stage">
            <div id="front" class="plane"><p>@thecodeblanks</p></div>
            <div id="back" class="plane"><p>Html</p></div>
            <div id="right" class="plane"><p>Css</p></div>
            <div id="left" class="plane"><p>Javascript</p></div>
            <div id="top" class="plane"><p>Jquery</p></div>
            <div id="bottom" class="plane"><p>For You</p></div>
        </div>
    </body>
</html>
CSS
body {
    display: flex;
    align-items: center;
    justify-content: center;
    perspective: 800px;
    background-color: transparent;
}
#stage {
    width: 200px;
    height: 200px;
    margin: 50px auto;
    transform-style: preserve-3d;
    animation: rotate 10s linear infinite;
}
.plane {
    position: absolute;
    width: 200px;
    height: 200px;
    border: 2px solid black;
    background: rgba(0, 150, 255, 0.5);
    opacity: 0.8;
    display: flex;
    justify-content: center;
    align-items: center;
}
.plane p {
    color: white;
    font-size: 24px;
    font-weight: bold;
} /* Yazı stili */
#front {
    transform: translateZ(100px);
}
#back {
    transform: rotateY(180deg) translateZ(100px);
}
#right {
    transform: rotateY(90deg) translateZ(100px);
}
#left {
    transform: rotateY(-90deg) translateZ(100px);
}
#top {
    transform: rotateX(90deg) translateZ(100px);
}
#bottom {
    transform: rotateX(-90deg) translateZ(100px);
}

@keyframes rotate {
    from {
        transform: rotateX(0deg) rotateY(0deg);
    }
    to {
        transform: rotateX(360deg) rotateY(360deg);
    }
}

About this snippet

No canvas, no WebGL: this rotating cube is made of six ordinary div elements positioned in 3D space with CSS. Each face carries its own label (HTML, CSS, JavaScript and so on), and the whole cube spins on the X and Y axes in a 10-second loop.

How it works

  • perspective: 800px on the parent gives the scene depth; smaller values exaggerate the 3D effect.
  • #stage uses transform-style: preserve-3d so its children keep their positions in 3D instead of being flattened.
  • Every face is first rotated to face its direction (rotateY(90deg), rotateX(-90deg) …) and then pushed outwards with translateZ(100px), which is half the cube's 200 px width.
  • The rotate keyframes turn the stage from 0° to 360° on both axes with linear timing for a constant speed.

How to use it

  1. Copy the HTML structure with the six .plane faces and the CSS.
  2. To change the size, update width/height of #stage and .plane, then set every translateZ to half of that value.
  3. Replace the text in each <p>, or put images inside the faces for a product or logo cube.
  4. Change 10s in the animation to speed the rotation up or down.

Tips

Add backface-visibility: hidden to the faces if you use opaque backgrounds. To make the cube interactive, pause it with animation-play-state: paused on hover.

Comments 0

No comments yet. Be the first to comment.