Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <h1>3D Carousel</h1>

<div class="carousel_wrapper">
  <div class="carousel">
    <div class="slide one">
      <img src="" />
    <div class="slide two">
      <img src="" />
    <div class="slide three">
      <img src="" />
    <div class="slide four">
      <img src="" />
    <div class="slide five">
      <img src="" />
    <div class="slide six">
      <img src="" />
    <div class="slide seven">
      <img src="" />
    <div class="slide eight">
      <img src="" />
    <div class="slide nine">
      <img src="" />
  </div><!-- / .carousel -->
</div><!-- / .carousel_wrapper -->



                *, *::before, *::after {
  box-sizing: border-box; /* Too much math below to be concerned with standard CSS Box Model element dimensions calculations. Let's not have to account for padding/margins/borders on anything here. */

body {
  margin: 0;
  background-image: url('');
  background-attachment: fixed;
  background-size: cover;

h1 {
  margin: 0 0 30px 0;
  padding: 20px;
  background-color: rgba(20,20,20,0.9);
  color: #fff;
  text-align: center;
  font-family: Arial;
  text-transform: uppercase;
  box-shadow: 0 0 20px -1px #efefef;

.carousel_wrapper {
  position: relative;
  width: 320px;
  margin: 100px auto 0 auto;
  perspective: 1000px;

.carousel {
  position: absolute;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transform: rotateY(-360deg) translateZ(-412px); /* add reverse transformation from the slides */
  animation: swirl 40s steps(10000, end) infinite; /* run `swirl` animation (defined at end of CSS) infitely, with animation lasting 40 seconds, and 10,000 steps between the FROM and TO values in the animation for a smooth rotation */

.slide {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 300px;
  height: 187px;

.slide img {
  width: 280px;
  height: 175px;
  border: 3px inset rgba(47, 115, 201, 0.75);
  box-shadow: 0 0 15px 3px rgba(110, 72, 221, 0.9);

9 Slides total: 360 Degrees (full circle) --> 360/9 = 40 --> our increment for rotation

Some math. Consider how the carousel will be set up. It's going to be a 3D circle, like an orbit. The orientation will be such that it would be like setting a ring down on a table, then bending down and looking at the ring head on from the edge of the table. The main "front" image will be entirely front-facing. The other images will be rotated slightly to make a full circle. You could sketch this out in 2D from a bird's eye view, and you'd end up with a picture like the following:

Each triangle/piece would be a slide, hence 9 pieces. That being said, let's do some calculations, but we'll use the dimensions of our elements rather than those in the picture.

So, we're rotating all the slides in 40º increments relative to each other, because 360º makes a full circle, and we have 9 elements: 360/9 = 40

In the picture above, we want to find the radius of the circle (which isn't exactly a circle because it's made up of triangles). So we can cut each triangle in half and solve for `r` (radius). We can solve for `r` using some geometry and our own elements' dimensions. 

The width of the slides is 300px. We're going to split those triangles in half and use the TANGENT function in geometry/trigonemty to solve for `r`. And since we're splitting each of the 9 triangles (the slides) in half for this, we need to account for the fact that our key angle is now going to be 20º and not 40º. We can solve for `r` by taking our smaller triangles' width (150px) and dividing by the tangent of 20º (in degrees, not radians). So:

   r =  -----------

Here's a screenshot of me doing the calculations in JavaScript, right in the browser console!

Math things:

So, `r` is (about) 412px long! This means we need to TRANSLATE the slides in the Z 3-dimensional plane by 412px. This should be done AFTER the rotateY transformation.
*/ {
  transform: rotateY(0deg) translateZ(412px);
.slide.two {
  transform: rotateY(40deg) translateZ(412px);
.slide.three {
  transform: rotateY(80deg) translateZ(412px);
.slide.four {
  transform: rotateY(120deg) translateZ(412px);
.slide.five {
  transform: rotateY(160deg) translateZ(412px);
.slide.six {
  transform: rotateY(200deg) translateZ(412px);
} {
  transform: rotateY(240deg) translateZ(412px);
.slide.eight {
  transform: rotateY(280deg) translateZ(412px);
.slide.nine {
  transform: rotateY(320deg) translateZ(412px);

Simply rotates the carousel around the Y axis by using rotateY and starting at initial value, -360º, and going to final value 0º, then resetting.

@keyframes swirl {   
  from {
    transform: rotateY(-360deg);
  to {
    transform: rotateY(0deg);


                // NOPE!