{"id":404,"date":"2025-07-23T21:29:00","date_gmt":"2025-07-23T18:29:00","guid":{"rendered":"https:\/\/html-online.com\/articles\/?p=404"},"modified":"2025-07-31T15:19:37","modified_gmt":"2025-07-31T12:19:37","slug":"css3-cube","status":"publish","type":"post","link":"https:\/\/html-online.com\/articles\/css3-cube\/","title":{"rendered":"Drawing Animated 3D Cube With CSS3 Transform"},"content":{"rendered":"<p>In this article I&#8217;m going to teach you how to draw a cube with CSS3 transitions. We will be able to rotate the cube with keyframes animation and <a href=\"\/articles\/category\/javascript\/\">JavaScript<\/a>. See the examples below. We can use this to make an <a href=\"\/articles\/rubiks-cube-solver-html-css-javascript\/\">online Rubik&#8217;s Cube solver<\/a>, for example.<\/p>\n<p class=\"aligncenter\"><iframe loading=\"lazy\" style=\"margin: auto; width: 400px; height: 250px; overflow: hidden;\" src=\"\/demo\/css3-cube\/cube-animation.html\" width=\"400\" height=\"400\" scrolling=\"no\">Iframes not supported<\/iframe><\/p>\n<p><!--more--><\/p>\n<p style=\"text-align: center;\">Cube animated using CSS keyframes<\/p>\n<h2>Live Demo<\/h2>\n<p>Below you can view test the script version. Click the rotation buttons to see the animated turns.<\/p>\n<p style=\"text-align: center;\"><iframe loading=\"lazy\" style=\"margin: auto; width: 350px; height: 350px; overflow: hidden;\" src=\"\/demo\/css3-cube\/\" width=\"400\" height=\"400\" scrolling=\"no\">Iframes not supported<\/iframe><\/p>\n<h2>The HTML Code<\/h2>\n<p>All you need is a wrapper and a div element for each side. Below the cube I added the links to control the cube rotations.<\/p>\n<pre style=\"background: #fff; color: #000;\"><span style=\"color: #1c02ff;\">&lt;<span style=\"font-weight: bold;\">div<\/span> <span style=\"font-style: italic;\">id<\/span>=<span style=\"color: #d80800;\">\"wrapD3Cube\"<\/span>&gt;<\/span>\n    <span style=\"color: #1c02ff;\">&lt;<span style=\"font-weight: bold;\">div<\/span> <span style=\"font-style: italic;\">id<\/span>=<span style=\"color: #d80800;\">\"D3Cube\"<\/span>&gt;<\/span>\n        <span style=\"color: #1c02ff;\">&lt;<span style=\"font-weight: bold;\">div<\/span> <span style=\"font-style: italic;\">id<\/span>=<span style=\"color: #d80800;\">\"side1\"<\/span>&gt;&lt;\/<span style=\"font-weight: bold;\">div<\/span>&gt;<\/span>\n        <span style=\"color: #1c02ff;\">&lt;<span style=\"font-weight: bold;\">div<\/span> <span style=\"font-style: italic;\">id<\/span>=<span style=\"color: #d80800;\">\"side2\"<\/span>&gt;&lt;\/<span style=\"font-weight: bold;\">div<\/span>&gt;<\/span>\n        <span style=\"color: #1c02ff;\">&lt;<span style=\"font-weight: bold;\">div<\/span> <span style=\"font-style: italic;\">id<\/span>=<span style=\"color: #d80800;\">\"side3\"<\/span>&gt;&lt;\/<span style=\"font-weight: bold;\">div<\/span>&gt;<\/span>\n        <span style=\"color: #1c02ff;\">&lt;<span style=\"font-weight: bold;\">div<\/span> <span style=\"font-style: italic;\">id<\/span>=<span style=\"color: #d80800;\">\"side4\"<\/span>&gt;&lt;\/<span style=\"font-weight: bold;\">div<\/span>&gt;<\/span>\n        <span style=\"color: #1c02ff;\">&lt;<span style=\"font-weight: bold;\">div<\/span> <span style=\"font-style: italic;\">id<\/span>=<span style=\"color: #d80800;\">\"side5\"<\/span>&gt;&lt;\/<span style=\"font-weight: bold;\">div<\/span>&gt;<\/span>\n        <span style=\"color: #1c02ff;\">&lt;<span style=\"font-weight: bold;\">div<\/span> <span style=\"font-style: italic;\">id<\/span>=<span style=\"color: #d80800;\">\"side6\"<\/span>&gt;&lt;\/<span style=\"font-weight: bold;\">div<\/span>&gt;<\/span>\n    <span style=\"color: #1c02ff;\">&lt;\/<span style=\"font-weight: bold;\">div<\/span>&gt;<\/span>\n<span style=\"color: #1c02ff;\">&lt;\/<span style=\"font-weight: bold;\">div<\/span>&gt;<\/span>\n<span style=\"color: #1c02ff;\">&lt;<span style=\"font-weight: bold;\">p<\/span> <span style=\"font-style: italic;\">style<\/span>=<span style=\"color: #d80800;\">\"text-align: center;\"<\/span>&gt;<\/span>\n    <span style=\"color: #1c02ff;\">&lt;<span style=\"font-weight: bold;\">a<\/span> <span style=\"font-style: italic;\">onclick<\/span>=<span style=\"color: #d80800;\">\"turnLeft()\"<\/span>&gt;<\/span>Left<span style=\"color: #1c02ff;\">&lt;\/<span style=\"font-weight: bold;\">a<\/span>&gt;<\/span>\n    <span style=\"color: #1c02ff;\">&lt;<span style=\"font-weight: bold;\">a<\/span> <span style=\"font-style: italic;\">onclick<\/span>=<span style=\"color: #d80800;\">\"turnRight()\"<\/span>&gt;<\/span>Right<span style=\"color: #1c02ff;\">&lt;\/<span style=\"font-weight: bold;\">a<\/span>&gt;<\/span> <span style=\"color: #1c02ff;\">&lt;<span style=\"font-weight: bold;\">br<\/span> \/&gt;<\/span>\n    <span style=\"color: #1c02ff;\">&lt;<span style=\"font-weight: bold;\">a<\/span> <span style=\"font-style: italic;\">onclick<\/span>=<span style=\"color: #d80800;\">\"flipCube()\"<\/span>&gt;<\/span>Flip<span style=\"color: #1c02ff;\">&lt;\/<span style=\"font-weight: bold;\">a<\/span>&gt;<\/span>\n<span style=\"color: #1c02ff;\">&lt;\/<span style=\"font-weight: bold;\">p<\/span>&gt;<\/span>\n<\/pre>\n<h2>The CSS Styles<\/h2>\n<p>I colored the object according to the color scheme of a Rubik&#8217;s Cube and set a slight opacity. The six sides of the cube are positioned with the transform property.<\/p>\n<pre style=\"background: #fff; color: #000;\"><span style=\"font-style: italic;\">#wrapD3Cube<\/span> {\n    <span style=\"color: #6d79de; font-weight: bold;\">width<\/span>: <span style=\"color: #cd0000; font-style: italic;\">250<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>;\n    <span style=\"color: #6d79de; font-weight: bold;\">height<\/span>: <span style=\"color: #cd0000; font-style: italic;\">213<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>;\n    <span style=\"color: #6d79de; font-weight: bold;\">margin<\/span>: <span style=\"color: #cd0000; font-style: italic;\">20<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span> <span style=\"color: #06960e; font-weight: bold;\">auto<\/span>;\n    <span style=\"color: #6d79de; font-weight: bold;\">background-color<\/span>: <span style=\"color: #c5060b; font-style: italic;\">#EEE<\/span>;\n}\n<span style=\"font-style: italic;\">#D3Cube<\/span> {\n    <span style=\"color: #6d79de; font-weight: bold;\">width<\/span>: <span style=\"color: #cd0000; font-style: italic;\">112<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>;\n    <span style=\"color: #6d79de; font-weight: bold;\">height<\/span>: <span style=\"color: #cd0000; font-style: italic;\">112<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>;\n    <span style=\"color: #6d79de; font-weight: bold;\">top<\/span>: <span style=\"color: #cd0000; font-style: italic;\">50<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>;\n    transform-style: preserve<span style=\"color: #cd0000; font-style: italic;\">-3<\/span>d;\n    -moz-transform-style: preserve<span style=\"color: #cd0000; font-style: italic;\">-3<\/span>d;\n    -webkit-transform-style: preserve<span style=\"color: #cd0000; font-style: italic;\">-3<\/span>d;\n    transform: rotateX(<span style=\"color: #cd0000; font-style: italic;\">-22<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) rotateY(<span style=\"color: #cd0000; font-style: italic;\">-38<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) rotateZ(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>);\n    -moz-transform: rotateX(<span style=\"color: #cd0000; font-style: italic;\">-22<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) rotateY(<span style=\"color: #cd0000; font-style: italic;\">-38<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) rotateZ(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>);\n    -webkit-transform: rotateX(<span style=\"color: #cd0000; font-style: italic;\">-22<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) rotateY(<span style=\"color: #cd0000; font-style: italic;\">-38<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) rotateZ(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>);\n    <span style=\"color: #6d79de; font-weight: bold;\">margin<\/span>: <span style=\"color: #06960e; font-weight: bold;\">auto<\/span>;\n    <span style=\"color: #6d79de; font-weight: bold;\">position<\/span>: <span style=\"color: #06960e; font-weight: bold;\">relative<\/span>;\n    -moz-transform-style: preserve<span style=\"color: #cd0000; font-style: italic;\">-3<\/span>d;\n    transform-style: preserve<span style=\"color: #cd0000; font-style: italic;\">-3<\/span>d;\n    -webkit-transition: <span style=\"color: #06960e; font-weight: bold;\">all<\/span> <span style=\"color: #cd0000; font-style: italic;\">0.5<span style=\"color: #0100b6; font-weight: bold;\">s<\/span><\/span> ease-in-out;\n    transition: <span style=\"color: #06960e; font-weight: bold;\">all<\/span> <span style=\"color: #cd0000; font-style: italic;\">0.5<span style=\"color: #0100b6; font-weight: bold;\">s<\/span><\/span> ease-in-out;\n}\n<span style=\"font-style: italic;\">#D3Cube<\/span> &gt; <span style=\"font-weight: bold;\">div<\/span> {\n    <span style=\"color: #6d79de; font-weight: bold;\">position<\/span>: <span style=\"color: #06960e; font-weight: bold;\">absolute<\/span>;\n    -webkit-transition: <span style=\"color: #06960e; font-weight: bold;\">all<\/span> <span style=\"color: #cd0000; font-style: italic;\">0.5<span style=\"color: #0100b6; font-weight: bold;\">s<\/span><\/span> ease-in-out;\n    transition: <span style=\"color: #06960e; font-weight: bold;\">all<\/span> <span style=\"color: #cd0000; font-style: italic;\">0.5<span style=\"color: #0100b6; font-weight: bold;\">s<\/span><\/span> ease-in-out;\n    <span style=\"color: #6d79de; font-weight: bold;\">width<\/span>: <span style=\"color: #cd0000; font-style: italic;\">112<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>;\n    <span style=\"color: #6d79de; font-weight: bold;\">height<\/span>: <span style=\"color: #cd0000; font-style: italic;\">112<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>;\n    <span style=\"color: #6d79de; font-weight: bold;\">float<\/span>: <span style=\"color: #06960e; font-weight: bold;\">left<\/span>;\n    <span style=\"color: #6d79de; font-weight: bold;\">overflow<\/span>: <span style=\"color: #06960e; font-weight: bold;\">hidden<\/span>;\n    <span style=\"color: #6d79de; font-weight: bold;\">opacity<\/span>: <span style=\"color: #cd0000; font-style: italic;\">0.85<\/span>;\n}\n<span style=\"font-style: italic;\">#side1<\/span> {\n    transform: rotatex(<span style=\"color: #cd0000; font-style: italic;\">90<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) translateX(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateY(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateZ(<span style=\"color: #cd0000; font-style: italic;\">56<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>);\n    -moz-transform: rotatex(<span style=\"color: #cd0000; font-style: italic;\">90<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) translateX(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateY(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateZ(<span style=\"color: #cd0000; font-style: italic;\">56<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>);\n    -webkit-transform: rotatex(<span style=\"color: #cd0000; font-style: italic;\">90<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) translateX(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateY(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateZ(<span style=\"color: #cd0000; font-style: italic;\">56<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>);\n    <span style=\"color: #6d79de; font-weight: bold;\">background-color<\/span>: <span style=\"color: #c5060b; font-style: italic;\">#FFF<\/span>;\n}\n<span style=\"font-style: italic;\">#side2<\/span> {\n    transform: rotateY(<span style=\"color: #cd0000; font-style: italic;\">-90<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) translateX(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateY(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateZ(<span style=\"color: #cd0000; font-style: italic;\">56<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>);\n    -moz-transform: rotateY(<span style=\"color: #cd0000; font-style: italic;\">-90<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) translateX(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateY(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateZ(<span style=\"color: #cd0000; font-style: italic;\">56<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>);\n    -webkit-transform: rotateY(<span style=\"color: #cd0000; font-style: italic;\">-90<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) translateX(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateY(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateZ(<span style=\"color: #cd0000; font-style: italic;\">56<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>);\n    <span style=\"color: #6d79de; font-weight: bold;\">background-color<\/span>: <span style=\"color: #c5060b; font-style: italic;\">#ffaf1c<\/span>;\n}\n<span style=\"font-style: italic;\">#side3<\/span> {\n    transform: translateX(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateY(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateZ(<span style=\"color: #cd0000; font-style: italic;\">56<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>);\n    -moz-transform: translateX(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateY(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateZ(<span style=\"color: #cd0000; font-style: italic;\">56<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>);\n    -webkit-transform: translateX(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateY(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateZ(<span style=\"color: #cd0000; font-style: italic;\">56<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>);\n    <span style=\"color: #6d79de; font-weight: bold;\">background-color<\/span>: <span style=\"color: #c5060b; font-style: italic;\">#58d568<\/span>;\n}\n<span style=\"font-style: italic;\">#side4<\/span> {\n    transform: rotateY(<span style=\"color: #cd0000; font-style: italic;\">90<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) translateX(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateY(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateZ(<span style=\"color: #cd0000; font-style: italic;\">56<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>);\n    -moz-transform: rotateY(<span style=\"color: #cd0000; font-style: italic;\">90<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) translateX(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateY(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateZ(<span style=\"color: #cd0000; font-style: italic;\">56<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>);\n    -webkit-transform: rotateY(<span style=\"color: #cd0000; font-style: italic;\">90<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) translateX(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateY(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateZ(<span style=\"color: #cd0000; font-style: italic;\">56<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>);\n    <span style=\"color: #6d79de; font-weight: bold;\">background-color<\/span>: <span style=\"color: #c5060b; font-style: italic;\">#ed3030<\/span>;\n}\n<span style=\"font-style: italic;\">#side5<\/span> {\n    transform: rotateY(<span style=\"color: #cd0000; font-style: italic;\">180<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) translateX(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateY(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateZ(<span style=\"color: #cd0000; font-style: italic;\">56<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>);\n    -moz-transform: rotateY(<span style=\"color: #cd0000; font-style: italic;\">180<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) translateX(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateY(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateZ(<span style=\"color: #cd0000; font-style: italic;\">56<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>);\n    -webkit-transform: rotateY(<span style=\"color: #cd0000; font-style: italic;\">180<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) translateX(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateY(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateZ(<span style=\"color: #cd0000; font-style: italic;\">56<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>);\n    <span style=\"color: #6d79de; font-weight: bold;\">background-color<\/span>: <span style=\"color: #c5060b; font-style: italic;\">#1c5ffe<\/span>;\n}\n<span style=\"font-style: italic;\">#side6<\/span> {\n    transform: rotateX(<span style=\"color: #cd0000; font-style: italic;\">-90<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) translateX(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateY(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateZ(<span style=\"color: #cd0000; font-style: italic;\">56<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>);\n    -moz-transform: rotateX(<span style=\"color: #cd0000; font-style: italic;\">-90<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) translateX(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateY(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateZ(<span style=\"color: #cd0000; font-style: italic;\">56<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>);\n    -webkit-transform: rotateX(<span style=\"color: #cd0000; font-style: italic;\">-90<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) translateX(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateY(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>) translateZ(<span style=\"color: #cd0000; font-style: italic;\">56<span style=\"color: #0100b6; font-weight: bold;\">px<\/span><\/span>);\n    <span style=\"color: #6d79de; font-weight: bold;\">background-color<\/span>: <span style=\"color: #c5060b; font-style: italic;\">#f2f215<\/span>;\n}\n<\/pre>\n<h2>The Script<\/h2>\n<p>The script manipulates the rotateX, rotateY and rotateZ values of the transform CSS property:<\/p>\n<pre style=\"background: #fff; color: #000;\">var cubex <span style=\"color: #687687;\">=<\/span> <span style=\"color: #687687;\">-<\/span><span style=\"color: #cd0000; font-style: italic;\">22<\/span>,    <span style=\"color: #00b418;\">\/\/ initial rotation<\/span>\ncubey <span style=\"color: #687687;\">=<\/span> <span style=\"color: #687687;\">-<\/span><span style=\"color: #cd0000; font-style: italic;\">38<\/span>,\ncubez <span style=\"color: #687687;\">=<\/span> <span style=\"color: #cd0000; font-style: italic;\">0<\/span>;\nfunction <span style=\"color: #0000a2; font-weight: bold;\">rotate<\/span>(variableName, degrees) {\n    <span style=\"color: #6d79de; font-weight: bold;\">window<\/span>[variableName] <span style=\"color: #687687;\">=<\/span> <span style=\"color: #6d79de; font-weight: bold;\">window<\/span>[variableName] <span style=\"color: #687687;\">+<\/span> degrees;\n    rotCube(cubex, cubey, cubez);\n}\nfunction <span style=\"color: #0000a2; font-weight: bold;\">rotCube<\/span>(degx, degy, degz){\n    segs <span style=\"color: #687687;\">=<\/span> <span style=\"color: #d80800;\">\"rotateX(\"<\/span><span style=\"color: #687687;\">+<\/span>degx<span style=\"color: #687687;\">+<\/span><span style=\"color: #d80800;\">\"deg) rotateY(\"<\/span><span style=\"color: #687687;\">+<\/span>degy<span style=\"color: #687687;\">+<\/span><span style=\"color: #d80800;\">\"deg) rotateZ(\"<\/span><span style=\"color: #687687;\">+<\/span>degz<span style=\"color: #687687;\">+<\/span><span style=\"color: #d80800;\">\"deg) translateX(0) translateY(0) translateZ(0)\"<\/span>;\n    <span style=\"color: #687687;\">$<\/span>(<span style=\"color: #d80800;\">'#D3Cube'<\/span>).css({<span style=\"color: #d80800;\">\"transform\"<\/span>:segs});\n}\nfunction <span style=\"color: #0000a2; font-weight: bold;\">turnRight<\/span>() {\n    rotate(<span style=\"color: #d80800;\">\"cubey\"<\/span>, <span style=\"color: #cd0000; font-style: italic;\">90<\/span>);\n}\nfunction <span style=\"color: #0000a2; font-weight: bold;\">turnLeft<\/span>() {\n    rotate(<span style=\"color: #d80800;\">\"cubey\"<\/span>, <span style=\"color: #687687;\">-<\/span><span style=\"color: #cd0000; font-style: italic;\">90<\/span>);\n}\nfunction <span style=\"color: #0000a2; font-weight: bold;\">flipCube<\/span>() {\n    rotate(<span style=\"color: #d80800;\">\"cubez\"<\/span>, <span style=\"color: #687687;\">-<\/span><span style=\"color: #cd0000; font-style: italic;\">180<\/span>);\n}\n<\/pre>\n<h2>Cube Rotation Animation With Keyframes<\/h2>\n<p>Rotating the cube with JavaScript is not the only way of animating the cube. We can use CSS keyframes to set a looping animation.<\/p>\n<p>In this case we need to add the adjustments below to our style sheet. This will smoothly change the rotateY value. Play with the code in <a href=\"https:\/\/html-css-js.com\/?html=%3C!DOCTYPE%20html%3E%0A%3Chtml%3E%0A%3Chead%3E%0A%3Ctitle%3EHTML%20CSS%20JS%3C\/title%3E%0A%3C\/head%3E%0A%3Cbody%3E%0A%3Cdiv%20i$*$d=%22wrapD3Cube%22%3E%0A%20%20%20%20%3Cdiv%20i$*$d=%22D3Cube%22%3E%0A%20%20%20%20%20%20%20%20%3Cdiv%20i$*$d=%22si$*$de1%22%3E%3C\/div%3E%0A%20%20%20%20%20%20%20%20%3Cdiv%20i$*$d=%22si$*$de2%22%3E%3C\/div%3E%0A%20%20%20%20%20%20%20%20%3Cdiv%20i$*$d=%22si$*$de3%22%3E%3C\/div%3E%0A%20%20%20%20%20%20%20%20%3Cdiv%20i$*$d=%22si$*$de4%22%3E%3C\/div%3E%0A%20%20%20%20%20%20%20%20%3Cdiv%20i$*$d=%22si$*$de5%22%3E%3C\/div%3E%0A%20%20%20%20%20%20%20%20%3Cdiv%20i$*$d=%22si$*$de6%22%3E%3C\/div%3E%0A%20%20%20%20%3C\/div%3E%0A%3C\/div%3E%0A%3Cp%20style=%22text-align:%20center;%22%3E%0A%20%20%20%20%3Ca%20onclick=%22turnLeft()%22%3ELeft%3C\/a%3E%0A%20%20%20%20%3Ca%20onclick=%22turnRight()%22%3ERight%3C\/a%3E%20%3Cbr%20\/%3E%0A%20%20%20%20%3Ca%20onclick=%22flipCube()%22%3EFlip%3C\/a%3E%0A%3C\/p%3E%0A%3C\/body%3E%0A%3C\/html%3E&#038;css=#wrapD3Cube%20%7B%0A%20%20%20%20wi$*$dth:%20250px;%0A%20%20%20%20height:%20213px;%0A%20%20%20%20margin:%2020px%20auto;%0A%20%20%20%20background-color:%20#EEE;%0A%7D%0A#D3Cube%20%7B%0A%20%20%20%20wi$*$dth:%20112px;%0A%20%20%20%20height:%20112px;%0A%20%20%20%20top:%2050px;%0A%20%20%20%20transform-style:%20preserve-3d;%0A%20%20%20%20-moz-transform-style:%20preserve-3d;%0A%20%20%20%20-webkit-transform-style:%20preserve-3d;%0A%20%20%20%20transform:%20rotateX(-22deg)%20rotateY(-38deg)%20rotateZ(0deg);%0A%20%20%20%20-moz-transform:%20rotateX(-22deg)%20rotateY(-38deg)%20rotateZ(0deg);%0A%20%20%20%20-webkit-transform:%20rotateX(-22deg)%20rotateY(-38deg)%20rotateZ(0deg);%0A%20%20%20%20margin:%20auto;%0A%20%20%20%20position:%20relative;%0A%20%20%20%20-moz-transform-style:%20preserve-3d;%0A%20%20%20%20transform-style:%20preserve-3d;%0A%20%20%20%20-webkit-transition:%20all%200.5s%20ease-in-out;%0A%20%20%20%20transition:%20all%200.5s%20ease-in-out;%0A%7D%0A#D3Cube%20%3E%20div%20%7B%0A%20%20%20%20position:%20absolute;%0A%20%20%20%20-webkit-transition:%20all%200.5s%20ease-in-out;%0A%20%20%20%20transition:%20all%200.5s%20ease-in-out;%0A%20%20%20%20wi$*$dth:%20112px;%0A%20%20%20%20height:%20112px;%0A%20%20%20%20float:%20left;%0A%20%20%20%20overflow:%20hi$*$dden;%0A%20%20%20%20opacity:%200.85;%0A%7D%0A#si$*$de1%20%7B%0A%20%20%20%20transform:%20rotatex(90deg)%20translateX(0px)%20translateY(0px)%20translateZ(56px);%0A%20%20%20%20-moz-transform:%20rotatex(90deg)%20translateX(0px)%20translateY(0px)%20translateZ(56px);%0A%20%20%20%20-webkit-transform:%20rotatex(90deg)%20translateX(0px)%20translateY(0px)%20translateZ(56px);%0A%20%20%20%20background-color:%20#FFF;%0A%7D%0A#si$*$de2%20%7B%0A%20%20%20%20transform:%20rotateY(-90deg)%20translateX(0px)%20translateY(0px)%20translateZ(56px);%0A%20%20%20%20-moz-transform:%20rotateY(-90deg)%20translateX(0px)%20translateY(0px)%20translateZ(56px);%0A%20%20%20%20-webkit-transform:%20rotateY(-90deg)%20translateX(0px)%20translateY(0px)%20translateZ(56px);%0A%20%20%20%20background-color:%20#ffaf1c;%0A%7D%0A#si$*$de3%20%7B%0A%20%20%20%20transform:%20translateX(0px)%20translateY(0px)%20translateZ(56px);%0A%20%20%20%20-moz-transform:%20translateX(0px)%20translateY(0px)%20translateZ(56px);%0A%20%20%20%20-webkit-transform:%20translateX(0px)%20translateY(0px)%20translateZ(56px);%0A%20%20%20%20background-color:%20#58d568;%0A%7D%0A#si$*$de4%20%7B%0A%20%20%20%20transform:%20rotateY(90deg)%20translateX(0px)%20translateY(0px)%20translateZ(56px);%0A%20%20%20%20-moz-transform:%20rotateY(90deg)%20translateX(0px)%20translateY(0px)%20translateZ(56px);%0A%20%20%20%20-webkit-transform:%20rotateY(90deg)%20translateX(0px)%20translateY(0px)%20translateZ(56px);%0A%20%20%20%20background-color:%20#ed3030;%0A%7D%0A#si$*$de5%20%7B%0A%20%20%20%20transform:%20rotateY(180deg)%20translateX(0px)%20translateY(0px)%20translateZ(56px);%0A%20%20%20%20-moz-transform:%20rotateY(180deg)%20translateX(0px)%20translateY(0px)%20translateZ(56px);%0A%20%20%20%20-webkit-transform:%20rotateY(180deg)%20translateX(0px)%20translateY(0px)%20translateZ(56px);%0A%20%20%20%20background-color:%20#1c5ffe;%0A%7D%0A#si$*$de6%20%7B%0A%20%20%20%20transform:%20rotateX(-90deg)%20translateX(0px)%20translateY(0px)%20translateZ(56px);%0A%20%20%20%20-moz-transform:%20rotateX(-90deg)%20translateX(0px)%20translateY(0px)%20translateZ(56px);%0A%20%20%20%20-webkit-transform:%20rotateX(-90deg)%20translateX(0px)%20translateY(0px)%20translateZ(56px);%0A%20%20%20%20background-color:%20#f2f215;%0A%7D%0A#D3Cube%20%7B%0A%20%20%20%20-webkit-animation:%20cubeRotation%205s%20infinite;%20\/*%20Safari%204.0%20-%208.0%20*\/%0A%20%20%20%20animation:%20cubeRotation%205s%20infinite;%0A%7D%0A@-webkit-keyframes%20cubeRotation%20%7B%0A%20%20%20%200%25%20%20%20%7B%20%20-webkit-transform:%20rotateX(-22deg)%20rotateY(-38deg)%20rotateZ(0deg);%20%20%20%7D%0A%20%20%20%2050%25%20%20%20%7B%20-webkit-transform:%20rotateX(-22deg)%20rotateY(-128deg)%20rotateZ(0deg);%20%20%7D%0A%20%20%20%20100%25%20%20%20%7B%20%20%20%20-webkit-transform:%20rotateX(-22deg)%20rotateY(-398deg)%20rotateZ(0deg);%20%20%7D%0A%7D%0A@keyframes%20cubeRotation%20%7B%0A%20%20%20%200%25%20%20%20%7B%20%20transform:%20rotateX(-22deg)%20rotateY(-38deg)%20rotateZ(0deg);%20%20%20%7D%0A%20%20%20%2050%25%20%20%20%7B%20transform:%20rotateX(-22deg)%20rotateY(-238deg)%20rotateZ(0deg);%20%20%7D%0A%20%20%20%20100%25%20%20%20%7B%20%20%20%20transform:%20rotateX(-22deg)%20rotateY(-398deg)%20rotateZ(0deg);%20%20%7D%0A%7D%0A%09%20%20&#038;js=var%20cubex%20=%20-22,%20%20%20%20\/\/%20initial%20rotation%0Acubey%20=%20-38,%0Acubez%20=%200;%0Afunction%20rotate(variableName,%20degrees)%20%7B%0A%20%20%20%20window%5BvariableName%5D%20=%20window%5BvariableName%5D%20+%20degrees;%0A%20%20%20%20rotCube(cubex,%20cubey,%20cubez);%0A%7D%0Afunction%20rotCube(degx,%20degy,%20degz)%7B%0A%20%20%20%20segs%20=%20%22rotateX(%22+degx+%22deg)%20rotateY(%22+degy+%22deg)%20rotateZ(%22+degz+%22deg)%20translateX(0)%20translateY(0)%20translateZ(0)%22;%0A%20%20%20%20$('#D3Cube').css(%7B%22transform%22:segs%7D);%0A%7D%0Afunction%20turnRight()%20%7B%0A%20%20%20%20rotate(%22cubey%22,%2090);%0A%7D%0Afunction%20turnLeft()%20%7B%0A%20%20%20%20rotate(%22cubey%22,%20-90);%0A%7D%0Afunction%20flipCube()%20%7B%0A%20%20%20%20rotate(%22cubez%22,%20-180);%0A%7D\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">the live HTML-CSS-Js editor<\/a>.<\/p>\n<pre style=\"background: #fff; color: #000;\"><span style=\"font-style: italic;\">#D3Cube<\/span> {\n    -webkit-animation: cubeRotation <span style=\"color: #cd0000; font-style: italic;\">5<span style=\"color: #0100b6; font-weight: bold;\">s<\/span><\/span> infinite; <span style=\"color: #00b418;\">\/* Safari 4.0 - 8.0 *\/<\/span>\n    animation: cubeRotation <span style=\"color: #cd0000; font-style: italic;\">5<span style=\"color: #0100b6; font-weight: bold;\">s<\/span><\/span> infinite;\n}\n@-webkit-keyframes cubeRotation {\n    0%   {  -webkit-transform: rotateX(<span style=\"color: #cd0000; font-style: italic;\">-22<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) rotateY(<span style=\"color: #cd0000; font-style: italic;\">-38<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) rotateZ(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>);   }\n    50%   { -webkit-transform: rotateX(<span style=\"color: #cd0000; font-style: italic;\">-22<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) rotateY(<span style=\"color: #cd0000; font-style: italic;\">-128<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) rotateZ(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>);  }\n    100%   {    -webkit-transform: rotateX(<span style=\"color: #cd0000; font-style: italic;\">-22<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) rotateY(<span style=\"color: #cd0000; font-style: italic;\">-398<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) rotateZ(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>);  }\n}\n@keyframes cubeRotation {\n    0%   {  transform: rotateX(<span style=\"color: #cd0000; font-style: italic;\">-22<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) rotateY(<span style=\"color: #cd0000; font-style: italic;\">-38<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) rotateZ(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>);   }\n    50%   { transform: rotateX(<span style=\"color: #cd0000; font-style: italic;\">-22<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) rotateY(<span style=\"color: #cd0000; font-style: italic;\">-238<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) rotateZ(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>);  }\n    100%   {    transform: rotateX(<span style=\"color: #cd0000; font-style: italic;\">-22<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) rotateY(<span style=\"color: #cd0000; font-style: italic;\">-398<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>) rotateZ(<span style=\"color: #cd0000; font-style: italic;\">0<span style=\"color: #0100b6; font-weight: bold;\">deg<\/span><\/span>);  }\n}\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"617\" height=\"361\" class=\"aligncenter size-full wp-image-405\" src=\"\/articles\/wp-content\/uploads\/2017\/10\/css3-transform-3d-cube.jpg\" alt=\"css3 transform 3D cube\" srcset=\"https:\/\/html-online.com\/articles\/wp-content\/uploads\/2017\/10\/css3-transform-3d-cube.jpg 617w, https:\/\/html-online.com\/articles\/wp-content\/uploads\/2017\/10\/css3-transform-3d-cube-300x176.jpg 300w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article I&#8217;m going to teach you how to draw a cube with CSS3 transitions. We will be able to rotate the cube with keyframes animation and JavaScript. See the examples below. We can use this to make an online Rubik&#8217;s Cube solver, for example. Iframes not supported<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,2,3,4,5],"tags":[],"class_list":["post-404","post","type-post","status-publish","format-standard","hentry","category-articles","category-css","category-freebies","category-html","category-javascript"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Drawing Animated 3D Cube With CSS3 Transform<\/title>\n<meta name=\"description\" content=\"In this article I&#039;m going to teach you how to draw a cube with CSS3 transitions. We will be able to rotate the cube with keyframes animation and JavaScript\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/html-online.com\/articles\/css3-cube\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Drawing Animated 3D Cube With CSS3 Transform\" \/>\n<meta property=\"og:description\" content=\"In this article I&#039;m going to teach you how to draw a cube with CSS3 transitions. We will be able to rotate the cube with keyframes animation and JavaScript\" \/>\n<meta property=\"og:url\" content=\"https:\/\/html-online.com\/articles\/css3-cube\/\" \/>\n<meta property=\"og:site_name\" content=\"HTML Online\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/htmlcoding\/\" \/>\n<meta property=\"article:published_time\" content=\"2025-07-23T18:29:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-07-31T12:19:37+00:00\" \/>\n<meta name=\"author\" content=\"HTML Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"HTML Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/html-online.com\/articles\/css3-cube\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/html-online.com\/articles\/css3-cube\/\"},\"author\":{\"name\":\"HTML Editor\",\"@id\":\"https:\/\/html-online.com\/articles\/#\/schema\/person\/019f9afa07f209153df0fecfc90b8c1d\"},\"headline\":\"Drawing Animated 3D Cube With CSS3 Transform\",\"datePublished\":\"2025-07-23T18:29:00+00:00\",\"dateModified\":\"2025-07-31T12:19:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/html-online.com\/articles\/css3-cube\/\"},\"wordCount\":222,\"publisher\":{\"@id\":\"https:\/\/html-online.com\/articles\/#organization\"},\"articleSection\":[\"Articles\",\"CSS\",\"Freebies\",\"HTML\",\"JavaScript\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/html-online.com\/articles\/css3-cube\/\",\"url\":\"https:\/\/html-online.com\/articles\/css3-cube\/\",\"name\":\"Drawing Animated 3D Cube With CSS3 Transform\",\"isPartOf\":{\"@id\":\"https:\/\/html-online.com\/articles\/#website\"},\"datePublished\":\"2025-07-23T18:29:00+00:00\",\"dateModified\":\"2025-07-31T12:19:37+00:00\",\"description\":\"In this article I'm going to teach you how to draw a cube with CSS3 transitions. We will be able to rotate the cube with keyframes animation and JavaScript\",\"breadcrumb\":{\"@id\":\"https:\/\/html-online.com\/articles\/css3-cube\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/html-online.com\/articles\/css3-cube\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/html-online.com\/articles\/css3-cube\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/html-online.com\/articles\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Drawing Animated 3D Cube With CSS3 Transform\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/html-online.com\/articles\/#website\",\"url\":\"https:\/\/html-online.com\/articles\/\",\"name\":\"HTML Online Articles\",\"description\":\"Tips, tricks, tutorials\u2026\",\"publisher\":{\"@id\":\"https:\/\/html-online.com\/articles\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/html-online.com\/articles\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/html-online.com\/articles\/#organization\",\"name\":\"HTML Online\",\"url\":\"https:\/\/html-online.com\/articles\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/html-online.com\/articles\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/html-online.com\/articles\/wp-content\/uploads\/2022\/06\/logo.jpg\",\"contentUrl\":\"https:\/\/html-online.com\/articles\/wp-content\/uploads\/2022\/06\/logo.jpg\",\"width\":350,\"height\":350,\"caption\":\"HTML Online\"},\"image\":{\"@id\":\"https:\/\/html-online.com\/articles\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/htmlcoding\/\",\"https:\/\/www.linkedin.com\/in\/ferencdenes\/\",\"https:\/\/www.youtube.com\/channel\/UCn38Jw1sJzbjVHO95Zp0Sww\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/html-online.com\/articles\/#\/schema\/person\/019f9afa07f209153df0fecfc90b8c1d\",\"name\":\"HTML Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/html-online.com\/articles\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/7c1d8f5e7f1dc3e261766a96ac50c6a907fa5c236e87ab73379c57c9114e92cd?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/7c1d8f5e7f1dc3e261766a96ac50c6a907fa5c236e87ab73379c57c9114e92cd?s=96&d=mm&r=g\",\"caption\":\"HTML Editor\"},\"description\":\"In 2013, while wrestling with a mountain of client articles and an uncooperative CMS, I decided enough was enough. So, I created an online HTML editor purely out of necessity (and mild frustration). What began as a tool for my own sanity quickly evolved into a gift for the world\u2014or at least for anyone trying to avoid breaking their website's code. Since then, I've shared my tech notes on my blog, which serves as both a handy reference and a digital diary of the adventures and misadventures of a coder.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/ferencdenes\/\",\"https:\/\/www.youtube.com\/@htmlg\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Drawing Animated 3D Cube With CSS3 Transform","description":"In this article I'm going to teach you how to draw a cube with CSS3 transitions. We will be able to rotate the cube with keyframes animation and JavaScript","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/html-online.com\/articles\/css3-cube\/","og_locale":"en_GB","og_type":"article","og_title":"Drawing Animated 3D Cube With CSS3 Transform","og_description":"In this article I'm going to teach you how to draw a cube with CSS3 transitions. We will be able to rotate the cube with keyframes animation and JavaScript","og_url":"https:\/\/html-online.com\/articles\/css3-cube\/","og_site_name":"HTML Online","article_publisher":"https:\/\/www.facebook.com\/htmlcoding\/","article_published_time":"2025-07-23T18:29:00+00:00","article_modified_time":"2025-07-31T12:19:37+00:00","author":"HTML Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"HTML Editor","Estimated reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/html-online.com\/articles\/css3-cube\/#article","isPartOf":{"@id":"https:\/\/html-online.com\/articles\/css3-cube\/"},"author":{"name":"HTML Editor","@id":"https:\/\/html-online.com\/articles\/#\/schema\/person\/019f9afa07f209153df0fecfc90b8c1d"},"headline":"Drawing Animated 3D Cube With CSS3 Transform","datePublished":"2025-07-23T18:29:00+00:00","dateModified":"2025-07-31T12:19:37+00:00","mainEntityOfPage":{"@id":"https:\/\/html-online.com\/articles\/css3-cube\/"},"wordCount":222,"publisher":{"@id":"https:\/\/html-online.com\/articles\/#organization"},"articleSection":["Articles","CSS","Freebies","HTML","JavaScript"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https:\/\/html-online.com\/articles\/css3-cube\/","url":"https:\/\/html-online.com\/articles\/css3-cube\/","name":"Drawing Animated 3D Cube With CSS3 Transform","isPartOf":{"@id":"https:\/\/html-online.com\/articles\/#website"},"datePublished":"2025-07-23T18:29:00+00:00","dateModified":"2025-07-31T12:19:37+00:00","description":"In this article I'm going to teach you how to draw a cube with CSS3 transitions. We will be able to rotate the cube with keyframes animation and JavaScript","breadcrumb":{"@id":"https:\/\/html-online.com\/articles\/css3-cube\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/html-online.com\/articles\/css3-cube\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/html-online.com\/articles\/css3-cube\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/html-online.com\/articles\/"},{"@type":"ListItem","position":2,"name":"Drawing Animated 3D Cube With CSS3 Transform"}]},{"@type":"WebSite","@id":"https:\/\/html-online.com\/articles\/#website","url":"https:\/\/html-online.com\/articles\/","name":"HTML Online Articles","description":"Tips, tricks, tutorials\u2026","publisher":{"@id":"https:\/\/html-online.com\/articles\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/html-online.com\/articles\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Organization","@id":"https:\/\/html-online.com\/articles\/#organization","name":"HTML Online","url":"https:\/\/html-online.com\/articles\/","logo":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/html-online.com\/articles\/#\/schema\/logo\/image\/","url":"https:\/\/html-online.com\/articles\/wp-content\/uploads\/2022\/06\/logo.jpg","contentUrl":"https:\/\/html-online.com\/articles\/wp-content\/uploads\/2022\/06\/logo.jpg","width":350,"height":350,"caption":"HTML Online"},"image":{"@id":"https:\/\/html-online.com\/articles\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/htmlcoding\/","https:\/\/www.linkedin.com\/in\/ferencdenes\/","https:\/\/www.youtube.com\/channel\/UCn38Jw1sJzbjVHO95Zp0Sww"]},{"@type":"Person","@id":"https:\/\/html-online.com\/articles\/#\/schema\/person\/019f9afa07f209153df0fecfc90b8c1d","name":"HTML Editor","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/html-online.com\/articles\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/7c1d8f5e7f1dc3e261766a96ac50c6a907fa5c236e87ab73379c57c9114e92cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7c1d8f5e7f1dc3e261766a96ac50c6a907fa5c236e87ab73379c57c9114e92cd?s=96&d=mm&r=g","caption":"HTML Editor"},"description":"In 2013, while wrestling with a mountain of client articles and an uncooperative CMS, I decided enough was enough. So, I created an online HTML editor purely out of necessity (and mild frustration). What began as a tool for my own sanity quickly evolved into a gift for the world\u2014or at least for anyone trying to avoid breaking their website's code. Since then, I've shared my tech notes on my blog, which serves as both a handy reference and a digital diary of the adventures and misadventures of a coder.","sameAs":["https:\/\/www.linkedin.com\/in\/ferencdenes\/","https:\/\/www.youtube.com\/@htmlg"]}]}},"_links":{"self":[{"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/posts\/404","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/comments?post=404"}],"version-history":[{"count":3,"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/posts\/404\/revisions"}],"predecessor-version":[{"id":2254,"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/posts\/404\/revisions\/2254"}],"wp:attachment":[{"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/media?parent=404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/categories?post=404"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/tags?post=404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}