Pen Settings

HTML

CSS

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

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

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.

HTML

              
                <h1>Copy to clipboard from a data source (array)</h1>
<div id="trigger">Copy to clipboard</div>

<textarea name="clipboardTextarea" id="clipboardTextarea"></textarea>

              
            
!

CSS

              
                #clipboardTextarea {
  overflow: hidden;
  max-height: 0px;
  max-width: 0px;
  resize: none;
  border: none;
  position: absolute;
  bottom: 0px;
  right: 0px;
  z-index: -10;
}
#clipboardTextarea:focus {
  outline: none;
}

/*simple demo styles*/
#trigger {
  padding: 1em;
  background-color: green;
  display: inline-block;
  border-radius: 10px;
  color: white;
  font-family: Arial, Helvetica, sans-serif;
}

#trigger:hover {
  cursor: pointer;
}
h1 {
  font-family: Arial, Helvetica, sans-serif;
}

              
            
!

JS

              
                // First, dynamically produce a list as an array. In my use case I programmed an array from other application data to yield a list of grocery items
var myList = [
  "egg x10",
  "basmati rice 300g",
  "banana x7",
  "apple x1",
  "onion x2"
];
//Have a play around with the array values

//will need a dom element to use execCommand but will hide with css from the user
var myTarget = document.getElementById("clipboardTextarea");

function createListOutput() {
  console.log('output fired')
  var myListOutput = "";
  for (var i = 0; i < myList.length; i++) {
    //check if list is NOT the last in the array, if last don't output a line break
    if (i != myList.length - 1) {
      let lineItem = myList[i] + "\n";
      myListOutput = myListOutput + lineItem;
    } else {
      let lineItem = myList[i];
      myListOutput = myListOutput + lineItem;
    }
  }
  myTarget.value = myListOutput;
  myTarget.select();
  myTarget.setSelectionRange(0, 99999); //for mobile
  document.execCommand("copy");
  console.log("Copied to clipboard"); //could respond with some visual feedback to user
  alert("Copied to clipboard");
}

document.getElementById("trigger").addEventListener("click", createListOutput, false);
              
            
!
999px

Console