Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              %h1 Interactive CSS 3D Transform

    Drag the square around. Also, use your mouse wheel to scale.


    perspective(500px) rotateX(0deg) rotateY(0deg) scale(1)

              @import compass

@import url(https://fonts.googleapis.com/css?family=Rokkitt)
@import url(https://fonts.googleapis.com/css?family=Numans)

  font-family: Numans

#tips, h1
  color: #444
  user-select: none
  margin: 5px
  width: 300px
  height: 300px
  background: #DD312F
  border: 5px solid #444
  color: #444
  margin: 50px auto
  cursor: move
  font-family: Rokkitt
  background: #002A38
  border: 1px solid #444
  color: #B98D00
  padding: 10px
    content: 'transform: '
    color: #D33683
              var el          = document.getElementById('transform'),
    css         = document.getElementById('css'),
    width       = el.clientWidth,
    height      = el.clientHeight,
    perspective = 500,
    rotateX     = 0,
    rotateY     = 0,
    scale       = 100,
    isDown      = false,
    reverse     = false,

function scaleVal() {
  var strScale = scale.toString();
  if (scale >= 100) {
    return parseFloat(strScale[0] + '.' +  strScale.slice(1));
  return parseFloat('0.' + strScale);

function updateTransform() {
  var pProp = 'perspective(' + perspective +  'px)',
      xProp = 'rotateX('     + rotateX     + 'deg)',
      yProp = 'rotateY('     + rotateY     + 'deg)',
      sProp = 'scale('       + scaleVal()  +    ')',
      props = [pProp, xProp, yProp, sProp].join(' ');
  el.style[Modernizr.prefixed('transform')] = props;
  css.innerText = props;

function wheel(e) {
  var delta = e.wheelDelta || -e.detail;
  scale += delta > 0 ? 5 : -5;

el.addEventListener('mousedown', function(e) {
  isDown = true;
  lastX  = e.clientX;
  lastY  = e.clientY;
}, false);

el.addEventListener('mousewheel', wheel, false);
el.addEventListener('DOMMouseScroll', wheel, false);

document.addEventListener('mousemove', function(e) {
  if (isDown) {
    xMultiplier = 180 / height / scaleVal();
    yMultiplier = 180 / width  / scaleVal();
    rotateX += (lastY - e.clientY) * xMultiplier;
    rotateY += (lastX - e.clientX) * yMultiplier * (reverse ? 1 : -1);
    rotateX  = Math.floor(rotateX % 360);
    rotateY  = Math.floor(rotateY % 360);
    reverse  = Math.abs(Math.floor(rotateX / 90) % 4) > 1;
    lastX    = e.clientX;
    lastY    = e.clientY;
}, false);

document.addEventListener('mouseup', function() {
  isDown  = false;
}, false);
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.