Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <h1>Preventing paste into an input field</h1>
<p>This example demonstrates how to stop a user from pasting content into a HTML input form field using JavaScript. Check the HTML and JavaScript panes for more details or scroll to the bottom to find a code example.</p>

<p>This example was created by <a href="https://dev.to/claireparker/how-to-prevent-pasting-into-input-fields-nn">Claire Parker-Jones</a> and I only forked it in case it was deleted or moved.

<div><label for="paste-ok">✅ You can paste in this field as normal</label></div>
<div><input type="text" id="paste-ok" /></div>

<div><label for="paste-no">🛑 You can't paste in this field: this uses the attribute <code>onpaste</code></label></div>
<div><input type="text" id="paste-no" onpaste="return false" />

<div><label for="paste-no-event">🛑 You can't paste in this field either: this uses an event listener attached to the input field</label></div>
<div><input type="text" id="paste-no-event" />

<p>📌 Works in modern browsers. The paste event is part of the Clipboard API. Check out the <a href="https://caniuse.com/#feat=clipboard">caniuse stats</a>.</p>

<h2>Code Example</h2>
<pre><code>&lt;input type="text" id="paste-no-event" /&gt;
  const pasteBox = document.getElementById("paste-no-event");
  pasteBox.onpaste = e => {
    return false;

<h2>Bypassing in Code</h2>

<p>Any of the following lines of code can remove the protection.</p>

document.getElementById("paste-no").onpaste=new function(){};

<p>I can bypass the protection from the console or by DOM editing</p>

              // All of this is for display only and does not affect the ability to paste.

input {
  height: 35px;
  width: 250px;
  border-radius: 10px;
  border: 1px solid black;
  font-size: 18px;
  padding: 3px;
  margin-bottom: 15px;

body {
  font-family: "Open Sans", sans-serif;
  font-size: 18px;

pre {
  background-color: #afafaf;
  padding: 20px;
  display: inline-block;

              const pasteBox = document.getElementById("paste-no-event");
pasteBox.onpaste = e => {
  return false;

// Alternative syntax:

// pasteBox.addEventListener('paste', e => {
//   e.preventDefault();
//   return false;
// });
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.