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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <p>Onclick copy the by Id onclick</p>
<input id="the_text" type="text" value="here's the copy" size="50">

<button onclick="copyById('the_text')">copy</button>


<p>Copy by previous sibling with input</p>

<input id="prev" type="text" value="here's the previous" size="50">

<button onclick="copyPreviousSibling(this)">copy</button>

<p>Copy by previous sibling html text</p>

<span>Just a simple span</span>

<button onclick="copyPreviousSibling(this)">copy</button>

<p>Copy by previous sibling with password</p>

<input id="prev" type="password" value="here's the password" size="50">

<button onclick="copyPreviousSibling(this)">copy</button>


<p>Use for pasting</p>
<textarea rows="6" cols="80">
</textarea>
              
            
!

CSS

              
                body {
  font-family: Helvetica, Arial, sans-serif;
  line-height: 1.5
}
input, button {
  font-size: 1rem
}
p {
  font-size: 1.3rem;
  margin: 2rem 0 .4rem 0;
}
              
            
!

JS

              
                // Author: Joseph Cowdell

copyText = function(textToCopy) {
  this.copied = false
  
  // Create textarea element
  const textarea = document.createElement('textarea')
  
  // Set the value of the text
  textarea.value = textToCopy
  
  // Make sure we cant change the text of the textarea
  textarea.setAttribute('readonly', '');
  
  // Hide the textarea off the screnn
  textarea.style.position = 'absolute';
  textarea.style.left = '-9999px';
  
  // Add the textarea to the page
  document.body.appendChild(textarea);

  // Copy the textarea
  textarea.select()

  try {
    var successful = document.execCommand('copy');
    this.copied = true
  } catch(err) {
    this.copied = false
  }

  textarea.remove()
}

copyById = function(id) {
  let text = document.getElementById(id)
  copyText(text.value)  
}

copyPreviousSibling = function(curr) {
  let el = curr.previousElementSibling
  if (el.value !== undefined) {
    copyText(el.value)  
  } else {
    copyText(el.textContent)
  }
}

// inpired by https://paulund.co.uk/javascript-copy-and-paste
              
            
!
999px

Console