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.


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.


                <div class="container">
  <p class="draggable" draggable="true">1</p>
  <p class="draggable" draggable="true">2</p>
<div class="container">
  <p class="draggable" draggable="true">3</p>
  <p class="draggable" draggable="true">4</p>

<!-- Side Links Only -->
<div class="side-links">
  <a href="" target="_blank" class="side-link side-link-youtube">
    <i class="fab fa-youtube-square side-link-icon"></i>
    <span class="side-link-text">View Tutorial</span>
  <a href="" target="_blank" class="side-link side-link-github side-link-icon">
    <i class="fab fa-github-square"></i>
    <span class="side-link-text">View GitHub</span>
  <a href="" target="_blank" class="side-link side-link-twitter">
    <i class="fab fa-twitter-square side-link-icon"></i>
    <span class="side-link-text">View Twitter</span>


                body {
  margin: 0;

.container {
  background-color: #333;
  padding: 1rem;
  margin-top: 1rem;

.draggable {
  padding: 1rem;
  background-color: white;
  border: 1px solid black;
  cursor: move;

.draggable.dragging {
  opacity: .5;

/* Background Styles Only */

@import url('');

* {
    font-family: Raleway;

.side-links {
  position: absolute;
  top: 15px;
  right: 15px;

.side-link {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  margin-bottom: 10px;
  color: white;
  width: 180px;
  padding: 10px 0;
  border-radius: 10px;

.side-link-youtube {
  background-color: red;

.side-link-twitter {
  background-color: #1DA1F2;

.side-link-github {
  background-color: #6e5494;

.side-link-text {
  margin-left: 10px;
  font-size: 18px;

.side-link-icon {
  color: white;
  font-size: 30px;


                const draggables = document.querySelectorAll('.draggable')
const containers = document.querySelectorAll('.container')

draggables.forEach(draggable => {
  draggable.addEventListener('dragstart', () => {

  draggable.addEventListener('dragend', () => {

containers.forEach(container => {
  container.addEventListener('dragover', e => {
    const afterElement = getDragAfterElement(container, e.clientY)
    const draggable = document.querySelector('.dragging')
    if (afterElement == null) {
    } else {
      container.insertBefore(draggable, afterElement)

function getDragAfterElement(container, y) {
  const draggableElements = [...container.querySelectorAll('.draggable:not(.dragging)')]

  return draggableElements.reduce((closest, child) => {
    const box = child.getBoundingClientRect()
    const offset = y - - box.height / 2
    if (offset < 0 && offset > closest.offset) {
      return { offset: offset, element: child }
    } else {
      return closest
  }, { offset: Number.NEGATIVE_INFINITY }).element