Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

Save Automatically?

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

              
                <main>
  <h2>Translate (-5vmin to 5vmin)</h2>
  <div><span id="tx" data-type="translateX">X</span><i class="ref">X</i></div>
  <div><span id="ty" data-type="translateY">Y</span><i class="ref">Y</i></div>
  <div><span id="tz" data-type="translateZ">Z</span><i class="ref">Z</i></div>
  <h2>Rotate (0deg to 360deg)</h2>
  <div><span id="rx" data-type="rotateX">X</span><i class="ref">X</i></div>
  <div><span id="ry" data-type="rotateY">Y</span><i class="ref">Y</i></div>
  <div><span id="rz" data-type="rotateZ">Z</span><i class="ref">Z</i></div>
  <h2>Scale (-2 to 2)</h2>
  <div><span id="sx" data-type="scaleX">X</span><i class="ref">X</i></div>
  <div><span id="sy" data-type="scaleY">Y</span><i class="ref">Y</i></div>
  <div><span id="sz" data-type="scaleZ">Z</span><i class="ref">Z</i><a href="https://tympanus.net/codrops/css_reference/scalez/" target="_blank">Why?</a></div>
</main>
<form>
  <div>
    <label for="backface">Backface Visible</label>
    <input type="checkbox" id="backface" checked/>
  </div>
  <div>
    <label for="original">Show Original</label>
    <input type="checkbox" id="original"/>
  </div>
  <div>
    <label for="perspective">Perspective (with units)</label>
    <input type="text" id="perspective" value="15vmin"/>
  </div>
  <div>
    <label for="origin">Origin</label>
    <input type="text" id="origin" value="50% 50% 0vmin"/>
  </div>
  <!--div>
    <label for="preserve3d">Preserve 3d</label>
    <input type="checkbox" id="preserve3d" checked/>
  </div-->
              
            
!

CSS

              
                main div {
  background: hsl(var(--hue, 173), var(--saturation, 65.5%), var(--lightness, 56%));
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  height: 30vmin;
  
  transform-style: var(--transform-style, flat);
  perspective: var(--perspective, 15vmin);
}
main div span, main div i {
  font-size: 10vmin;
  font-weight: 900;
  //display: flex;
  color: #252528;
  backface-visibility: var(--backface, visible);
  transform-origin: var(--origin, 50% 50% 0vmin);
  text-align: center;
}
main div i {
  position: absolute;
  right: 50%;
  bottom: 50%;
  border: 1px solid rgba(37,37,41,.1);
  transform: translate(50%,50%);
  z-index: -1;
  color: rgba(37,37,41,.2);
  opacity: var(--show-reference, 0);
}
main div span b {
  width: 7vmin;
  height: 2.5vmin;
  background: white;
  display: flex;
  font-weight: 500;
  font-size: 2vmin;
  text-transform: uppercase;
  justify-content: center;
  align-items: center;
}
main div a {
  position: absolute;
  top: 0;
  right: 0;
  padding: 1rem;
  color: #343456;
}
main h2 {
  grid-column: 1 / 5;
  background: hsl(var(--hue, 173), var(--saturation, 65.5%), var(--lightness, 31%));
  color: #fafcff;
  padding: .5rem 1rem;
}


html {
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
}
body {
  background: hsla(210,50%,6%, 1);
}
main {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
}

form {
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  flex-wrap: wrap;
  align-items: center;
  width: 100%;
  
  background: hsla(0,0%,0%,0);
  color: #fafcff;
  
  position: relative;
  z-index: 10;
}
form div {
  text-align: center;
  padding: 3vmin 3vmin;
}
label {
}
input[type=text] {
  display: block;
  font-size: 1rem;
  margin-top: .5rem;
}


main h2:nth-of-type(2),
main h2:nth-of-type(2) + div,
main h2:nth-of-type(2) + div + div,
main h2:nth-of-type(2) + div + div + div,
main h2:nth-of-type(2) + div + div + div + div{
  --hue: 348;
}
main h2:nth-of-type(3),
main h2:nth-of-type(3) + div,
main h2:nth-of-type(3) + div + div,
main h2:nth-of-type(3) + div + div + div,
main h2:nth-of-type(2) + div + div + div + div  {
  --hue: 208;
}
              
            
!

JS

              
                var rotates = Array.from(document.querySelectorAll('div span[data-type^=rotate]'));
var translates = Array.from(document.querySelectorAll('div span[data-type^=translate]'));
var scales = Array.from(document.querySelectorAll('div span[data-type^=scale]'));

const timing = {
  duration: 3000,
  iterations: Infinity,
}


rotates.forEach((item, i) => {
  var func = item.getAttribute('data-type');
  item.animate({
    transform: [func + '(0deg)', func + '(360deg)'] //e.g. rotateX(0deg) -> rotateX(360deg);
  }, timing);
  
  var parent = item.parentNode;
  parent.style.setProperty('--lightness', (56 + (7.5 * i)) + '%');
});

translates.forEach((item, i) => {
  var func = item.getAttribute('data-type');
  item.animate({
    transform: [func + '(-5vmin)', func + '(5vmin)'] //e.g translateX(-5vmin) -> translateX(5vmin) 
  }, Object.assign(timing, { direction: 'alternate' }));
  
  var parent = item.parentNode;
  parent.style.setProperty('--lightness', (61 + (7.5 * i)) + '%');
});

scales.forEach((item, i) => {
  var func = item.getAttribute('data-type');
  item.animate({
    transform: [func + '(-2)', func + '(2)'] //e.g scaleX(-2) -> scaleX(2) 
  }, Object.assign(timing, { direction: 'alternate' }));
  
  var parent = item.parentNode;
  parent.style.setProperty('--saturation', '80%')
  parent.style.setProperty('--lightness', (66 + (7.5 * i)) + '%');
});





//form
var docStyle = document.documentElement.style;
document.getElementById('perspective').addEventListener('input', e => {
  docStyle.setProperty('--perspective', e.currentTarget.value);
});
document.getElementById('origin').addEventListener('input', e => {
  docStyle.setProperty('--origin', e.currentTarget.value);
  console.log('transform-origin', getComputedStyle(rotates[0]).transformOrigin);
});

// document.getElementById('preserve3d').addEventListener('click', e => {
//   docStyle.setProperty('--transform-style', e.currentTarget.checked ? 'preserve-3d' : 'flat');
//   //console.log(getComputedStyle(rotates[0]).transformStyle);
// });

document.getElementById('backface').addEventListener('click', e => {
  docStyle.setProperty('--backface', e.currentTarget.checked ? 'visible' : 'hidden');
  //console.log(getComputedStyle(rotates[0]).backfaceVisibility);
});
document.getElementById('original').addEventListener('click', e => {
  docStyle.setProperty('--show-reference', e.currentTarget.checked ? 1 : 0);
});
              
            
!
999px

Console