Pen Settings

HTML

CSS

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

JavaScript

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

Packages

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.

Behavior

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.

HTML

              
                
  <div class="container">
    <main style="--length: 90">
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="ornament"></div>
    <div class="ornament"></div>
    <div class="ornament"></div>
    <div class="ornament"></div>
    <div class="ornament"></div>
    <div class="ornament"></div>
    <div class="ornament"></div>
    <div class="ornament"></div>
    <div class="ornament"></div>
    <div class="ornament"></div>
    <div class="ornament"></div>
    <div class="ornament"></div>
    <div class="ornament"></div>
    <div class="ornament"></div>
    <div class="ornament"></div>
    <div class="ornament"></div>
    <div class="ornament"></div>
    <div class="ornament"></div>
    <div class="ornament"></div>
    <div class="ornament"></div>
    <div class="ornament"></div>
    <div class="ornament"></div>
    <div class="ornament star"></div>
    <div class="ornament star"></div>
  </main>
</div>

<form>
  <div>
    <input id="stepA" type="radio" name="step" value="0" />
    <label for="stepA">1</label>
    <input id="stepB" type="radio" name="step" value="12" />
    <label for="stepB">2</label>
    <input id="stepC" type="radio" name="step" value="123" />
    <label for="stepC">3</label>
    <input id="stepD" type="radio" name="step" value="1234" checked />
    <label for="stepD">4</label>
    <input id="stepE" type="radio" name="step" value="12345" />
    <label for="stepE">5</label>
  </div>
  <div>
    <label for="rate">Spin Rate</label>
    <input id="rate" type="range" min="0" max="2" value="1" step=".025" />
  </div>
</form>
              
            
!

CSS

              
                main {
  width: 30vmin;
  height: 30vmin;
  border: 0vmin dashed white;
  position: relative;
  transform-style: preserve-3d;

  --base-transform: rotateX(0deg);
  transform-origin: 50% 50%;
  
  animation: display-case 2000ms infinite linear;
  border-radius: 50%;
}

@media (prefers-reduced-motion) {
  main {
    animation-play-state: paused;
  }
}

@keyframes display-case {
  0% {
    transform: var(--base-transform) rotateZ(0turn);
  }
  100% {
    transform: var(--base-transform) rotateZ(-1turn);
  }
}

.container {
  width: 30vmin;
  height: 30vmin;
  transform-style: preserve-3d;
  transform: rotateY(-.05turn);
  transition: transform 1000ms ease-in-out;
  transform-origin: 50% 50%;
}

.tree {
  width: 3.5vmin;
  height: 1vmin;
  background: hsl(133, 50%, 40%);
  position: absolute;
  top: 50%;
  left: 50%;

  transition: transform 1000ms ease-in-out;

  transform: translate(-50%, -50%) var(--base-rotate, rotateZ(0turn))
    var(--base-offset, translateX(0vmin)) var(--depth, translateZ(0vmin))
    var(--tilt, rotateX(0deg)) scaleY(calc(var(--i) * 0.09));
}
.ornament {
  width: 3vmin;
  height: 3vmin;
  background: hsl(calc(var(--i) * 28), 90%, 54%);
  opacity: 1;
  transition: 1600ms cubic-bezier(1,0,.5,.5);
  transition-property: opacity, transform;
  border-radius: 50%;
  transform-style: preserve-3d;
  
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) var(--base-rotate, rotateZ(0turn))
    var(--base-offset, translateX(0vmin)) var(--depth, translateZ(0vmin))
    var(--tilt, rotateX(0deg) rotateY(0deg));
}
.star {
  width: 8vmin;
  height: 8vmin;
  background: hsl(28, 90%, 54%);
  opacity: 0;
  clip-path: polygon(100% 34%, 10% 90%, 50% 0%, 90% 90%, 0% 34%);
}

[data-steps*="1"] .tree,
[data-step-1] .tree {
  --base-rotate: rotateZ(calc(var(--i) * -30deg));
}

[data-steps*="2"] .tree,
[data-step-2] .tree {
  --base-offset: translateX(calc(var(--i) * -0.325vmin));
}

[data-steps*="3"] .container,
[data-step-3] .container {
  transform: rotateX(-.275turn) translateZ(30vmin);
}

[data-steps*="4"] .tree,
[data-step-4] .tree {
  --depth: translateZ(calc(calc(var(--length) - var(--i))  * -0.75vmin));
  --tilt: rotateX(calc(var(--i) * 0.1deg + 1deg));
}

[data-steps*="5"] .ornament,
[data-step-5] .ornament {
  opacity: 1;
  --base-rotate: rotateZ(calc(var(--i) * -30deg));
  --base-offset: translateX(calc(var(--i) * -0.3725vmin));
  --depth: translateZ(calc(calc(var(--length) - var(--i))  * -0.75vmin));
  --tilt: rotateX(80deg) rotateY(60deg);
  transition-timing-function: cubic-bezier(.5,.5,0,1);
}
[data-steps*="5"] .star,
[data-step-5] .star {
  opacity: 1;
  --base-rotate: rotateZ(0deg);
  --base-offset: translateX(0vmin);
  --depth: translateZ(calc(90 * -0.75vmin));
  --tilt: rotateX(90deg) rotateY(0deg);
  transition-timing-function: cubic-bezier(.5,.5,0,1);
}
[data-steps*="5"] .star:last-of-type,
[data-step-5] .star:last-of-type {
  background: hsl(38, 90%, 54%);
  --tilt: rotateX(90deg) rotateY(90deg);
}







body {
  display: flex;
  height: 100vh;
  background: radial-gradient(circle, hsl(343, 100%, 8%), hsl(343, 100%, 14%));
  justify-content: center;
  align-items: center;
  perspective: 500vmin;
  perspective-origin: 50% 0%;
  overflow: hidden;
  padding-bottom: 4rem;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

form {
  position: absolute;
  bottom: 1rem;
  display: flex;
  flex-direction: column;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

input[type="radio"],
input[type="checkbox"]{
  opacity: 0;
  position: absolute;
}
label {
  color: white;
}

input + label {
  width: 2.5rem;
  height: 2.5rem;
  border: .125rem solid white;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  color: white;
  margin: 0 .5rem;
  transition: all 300ms linear;
  background: hsla(343,100%,50%,1)
  
}
input:checked + label ~ label {
  opacity: .67;
  border: 0rem solid white;
  scale: .8;
  background: hsla(343,100%,50%,.2)
} 

form > div {
  display: flex;
}
form > div:last-child  {
  flex-direction: column;
  margin-top: 1rem;
}

              
            
!

JS

              
                const main = document.querySelector("main");
const parts = document.querySelectorAll(".tree");
const ornaments = document.querySelectorAll(".ornament");
document.documentElement.setAttribute('data-steps', '1234');

parts.forEach((part, i) => {
  part.style.setProperty('--i', i);
});
ornaments.forEach((part, i) => {
  part.style.setProperty('--i', i * 3.6 + 12); //maaaagic numbers!
});


// Show different steps to get to the tree
const steps = document.querySelectorAll('input[type="radio"]');

steps.forEach((step) => {
  step.addEventListener('click', (e) => {
    document.documentElement.setAttribute('data-steps', e.currentTarget.value);
  });
});




// Update Playback Rate
const rate = document.getElementById('rate');

const updateRate = e => {
  if (main.getAnimations) {
    const animation = main.getAnimations()[0];
    if (animation) {
      if (animation.playState === 'paused') {
        animation.play();
      }
      animation.playbackRate = parseFloat(e.currentTarget.value);
    }
  }
};

rate.addEventListener('input', updateRate);

              
            
!
999px

Console