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

              
                <button class="dqpl-button-secondary" type="button" data-dialog-id="demo-2">Modal Trigger</button>

<div class="dqpl-modal demo-modal" role="dialog" id="demo-2" aria-labelledby="form-modal-heading">
  <div class="dqpl-dialog-inner">
    <div class="dqpl-modal-header">
      <h2 id="form-modal-heading">Demo Modal</h2>
      <button class="dqpl-close" type="button">
        <div class="fa fa-close" aria-hidden="true"></div>
        <div class="dqpl-offscreen">Close</div>
      </button>
    </div>
    <div class="dqpl-content" tabindex="-1" aria-label="Ingredients">
      <h3>Ingredients</h3>
      <div class="dqpl-field-wrap">
        <label class="dqpl-label dqpl-required" for="x_2_2494">
          <span>Ingredient 1</span>
        </label>
        <input class="dqpl-text-input" id="x_2_2494" aria-invalid="false" value="1 pound ground beef">
      </div>
      <div id="added-bin"></div>
      <button id="add" type="button" class="dqpl-link">+ Add another ingredient</button>
    </div>
    <div class="dqpl-modal-footer">
      <button class="dqpl-button-primary dqpl-cancel" type="button">Save</button>
      <button class="dqpl-button-secondary dqpl-cancel" type="button">Cancel</button>
    </div>
  </div>
</div
              
            
!

CSS

              
                button.dqpl-button-secondary {
  margin: 15px;
}

.dqpl-modal.demo-modal .dqpl-dialog-inner {
  top: 50px;
}

.dqpl-field-wrap:first-of-type {
  margin-top: 15px;
}

.dqpl-field-wrap {
  margin-bottom: 0;
}

..dqpl-modal .dqpl-dialog-inner .dqpl-content {
  position: relative;
}

.dqpl-modal .dqpl-dialog-inner .dqpl-content::before {
  content: "";
  position: absolute;
  left: 4px;
  background-color: transparent;
  top: 50px;
  bottom: 0;
  width: 6px;
}

.dqpl-modal .dqpl-dialog-inner .dqpl-content:focus {
  outline: 0;
}

.dqpl-modal .dqpl-dialog-inner .dqpl-content:focus::before {
  background-color: #283640;
}

.dqpl-modal .dqpl-dialog-inner .dqpl-content .dqpl-text-input {
  width: 90%;
}

.dqpl-text-input:focus {
  outline: 0;
}

.dqpl-link {
  margin-bottom: 5px;
}

.delete {
  position: absolute;
  top: 21px;
  right: 0;
  color: #666;
  font-size: 16px;
  background-color: transparent;
}

.added-input-wrap {
  position: relative;
}

              
            
!

JS

              
                setTimeout(() => {
  var e = new Event('dqpl:ready');
  document.dispatchEvent(e);
}, 700);

var id = 0;

function generateInput() {
  id++;
  var inputId = 'added-' + id;
  return [
    '<div class="dqpl-field-wrap">',
    '<label class="dqpl-label" for="' + inputId + '">',
    '<span>Ingredient ' + (id + 1) + '</span>',
    '</label>',
    '<input class="dqpl-text-input" id="' + inputId + '">',
    '</div>',
    '<button type="button" class="delete" aria-label="Remove Ingredient ' + (id + 1) +'">',
    '<div aria-hidden="true" class="fa fa-trash"></div>',
    '</button>'
  ].join('');
}

function handleAdd() {
  var newInput = document.createElement('div');
  newInput.className = 'added-input-wrap';
  newInput.innerHTML = generateInput();
  document.getElementById('added-bin').appendChild(newInput);
  newInput.querySelector('input').focus(); 
}

function handleDelete(target) {
  var wrapper = target.parentNode;
  wrapper.parentNode.removeChild(wrapper);
  document.querySelector('.dqpl-content').focus();
}

document.addEventListener('click', function (e) {
  if (e.target.id === 'add') {
    handleAdd();
  } else if (e.target.classList.contains('delete')) {
    handleDelete(e.target);
  }
});
              
            
!
999px

Console