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 id="myWindow" class="window">
	<div class="window-top">
		<button class="round green"></button><button class="round yellow"></button><button class="round red"></button>
	</div>
	<div class="window-content">
		&gt; run MyNiftyProgram on Window 1
		<br />
		&gt;
		<br />
		&gt;&gt; Hello World
	</div>
	<input class="window-input" type="text" />
</div>

<div id="myWindow2" class="window">
	<div class="window-top-no-bind">
		<button class="round green"></button><button class="round yellow"></button><button class="round red"></button>
	</div>
	<div class="window-content">
		&gt; run MyNiftyProgram2 on Window 2
		<br />
		&gt;
		<br />
		&gt;&gt; World Hello
	</div>
	<input class="window-input" type="text" />
</div>
              
            
!

CSS

              
                body {
	background: #333;
}

.window {
	position: fixed;
	width: 400px;
	height: 250px;
	border-radius: 10px;
	border: none;
	box-shadow: 1px 1px 4px rgba(0,0,0,0,0.9), -1px 1px 4px rgba(0,0,0,0,0.9);
	background: #fff;
}

.window-content {
	background: #000;
	color: #fff;
	height: 100%;
	font-family: monospace;
	padding: 5px;
}

.window-input {
	display: block;
	font-family: monospace;
	width: calc(100% - 12px);
	background-color: #000;
	color: #fff;
	border: 4px solid #fff;
	border-bottom-right-radius: 5px;
	border-bottom-left-radius: 5px;
	padding: 2px;
	position: relative;
	bottom: 0;
	left: 0;
	right: 0;
	outline: 0;
}

.window-top, .window-top-no-bind {
	cursor: move;
	text-align: right;
	height: 20px;
	border-bottom: 1px solid rgba(0,0,0,0.5);
	border-top-right-radius: 5px;
	border-top-left-radius: 5px;
	padding: 5px;
	background-color: #ddd;
}

.window-top-no-bind {
	cursor: inherit;
}

.round {
	height: 16px;
	width: 16px;
	border-radius: 50%;
	border: none;
	margin-right: 6px;
	box-shadow: 1px 1px 2px #000;
}

.green {
	background-color: limegreen;
}

.yellow {
	background-color: yellow;
}

.red {
	cursor: pointer;
	background-color: red;
}

#myWindow {
	z-index: 999;
}

#myWindow2 {
	top: 0;
	left: 500px;
}
              
            
!

JS

              
                // You can choose to have an element with the class "window-top" inside of your draggable window that will act as the "handle" for the window or it will attach to the element itself

function makeDraggable (element) {
    // Make an element draggable (or if it has a .window-top class, drag based on the .window-top element)
    let currentPosX = 0, currentPosY = 0, previousPosX = 0, previousPosY = 0;

		// If there is a window-top classed element, attach to that element instead of full window
    if (element.querySelector('.window-top')) {
        // If present, the window-top element is where you move the parent element from
        element.querySelector('.window-top').onmousedown = dragMouseDown;
    } 
    else {
        // Otherwise, move the element itself
        element.onmousedown = dragMouseDown;
    }

    function dragMouseDown (e) {
        // Prevent any default action on this element (you can remove if you need this element to perform its default action)
        e.preventDefault();
        // Get the mouse cursor position and set the initial previous positions to begin
        previousPosX = e.clientX;
        previousPosY = e.clientY;
        // When the mouse is let go, call the closing event
        document.onmouseup = closeDragElement;
        // call a function whenever the cursor moves
        document.onmousemove = elementDrag;
    }

    function elementDrag (e) {
        // Prevent any default action on this element (you can remove if you need this element to perform its default action)
        e.preventDefault();
        // Calculate the new cursor position by using the previous x and y positions of the mouse
        currentPosX = previousPosX - e.clientX;
        currentPosY = previousPosY - e.clientY;
        // Replace the previous positions with the new x and y positions of the mouse
        previousPosX = e.clientX;
        previousPosY = e.clientY;
        // Set the element's new position
        element.style.top = (element.offsetTop - currentPosY) + 'px';
        element.style.left = (element.offsetLeft - currentPosX) + 'px';
    }

    function closeDragElement () {
        // Stop moving when mouse button is released and release events
        document.onmouseup = null;
        document.onmousemove = null;
    }
}

// Make myWindow and myWindow2 draggable in different ways...

// myWindow will only be able to be moved via the top bar (.window-top element). The main element does nothing on mouse down.
makeDraggable(document.querySelector('#myWindow'));

// myWindow2 will be able to moved by grabbing the entire element
makeDraggable(document.querySelector('#myWindow2'));

//Close the window on click of a red button
document.addEventListener('click', e => {
	if (e.target.closest('.round.red')) {
		e.target.closest('.window').remove();
	}
});
              
            
!
999px

Console