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.


                <div id="ex1" class="container">
  <div id="ex1-layer" class="box">
drag me


                .container {
  height: 100vh;
  width: 100vw;
  display: flex;
  align-items: center;
  justify-content: center;
.box {
  cursor: move;
  border: 2px solid red;
  height: 100px;
  width: 100px;
  position: absolute;


                let constrain = 20;
let mouseOverContainer = document.getElementById("ex1");
let ex1Layer = document.getElementById("ex1-layer");

let pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;

ex1Layer.onmousedown = dragMouseDown;

function dragMouseDown(e) {
    e = e || window.event;
    pos3 = e.clientX;
    pos4 = e.clientY;
    document.onmouseup = closeDragElement;
    document.onmousemove = elementDrag;

function elementDrag(e) {
  e = e || window.event;
  // calculate the new cursor position:
  pos1 = pos3 - e.clientX;
  pos2 = pos4 - e.clientY;
  pos3 = e.clientX;
  pos4 = e.clientY;
  // set the element's new position:
  if( == ex1Layer) { = ( - pos2) + "px"; = ( - pos1) + "px";    
function closeDragElement() {
  // stop moving when mouse button is released:
 document.onmouseup = null;
 document.onmousemove = null;

function transforms(x, y, el) {
  let box = el.getBoundingClientRect();
  let calcX = -(y - window.innerHeight / 2) / constrain;
  let calcY = (x - window.innerWidth / 2) / constrain;
  return "perspective(100px) "
    + "   rotateX("+ calcX +"deg) "
    + "   rotateY("+ calcY +"deg) ";

 function transformElement(el, xyEl) {  = transforms.apply(null, xyEl);

mouseOverContainer.onmousemove = function(e) {
  let xy = [e.clientX, e.clientY];
  let position = xy.concat([ex1Layer]);

    transformElement(ex1Layer, position);