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 id="wrapper">
  <div id="fileDropBox">Drop files here.</div>
  <script src="utilities.js" type="text/javascript"></script>
  <!-- Provides the alert() method. -->


                * {
  font-family: segoe, sans-serif;

#wrapper {
  margin:0 auto;
#fileDropBox {
  width: 20em;
  line-height: 10em;
  border: 1px dashed gray;
  text-align: center;
  color: gray;
  border-radius: 7px;


                var message = [];
if (!window.FileReader) {
  message = '<p>The ' +
    '<a href=""        target="_blank">File API</a>s ' +
    'are not fully supported by this browser.</p>' +
    '<p>Upgrade your browser to the latest version.</p>';
  document.querySelector('body').innerHTML = message;
} else {
  // Set up the file drag and drop listeners:         
  document.getElementById('fileDropBox').addEventListener('dragover', handleDragOver, false);
  document.getElementById('fileDropBox').addEventListener('drop', handleFileSelection, false);

function sanitizeHTML(htmlString) {
  var tmp = document.createElement('div');
  return tmp.innerHTML;
} // stripHtmlFromText

function handleDragOver(evt) {
  evt.stopPropagation(); // Do not allow the dragover event to bubble.
  evt.preventDefault(); // Prevent default dragover event behavior.
} // handleDragOver

function displayFileText(evt) {
  var fileString =; // Obtain the file contents, which was read into memory.
  // is a FileReader object, not a File object; so window.URL.createObject( won't work here!
  alert(sanitizeHTML(fileString), {
    width: 40,
    tile: true
  }); // sanitizeHTML() is used in case the user selects one or more HTML or HTML-like files
} // displayFileText

function handleFileReadAbort(evt) {
  alert("File read aborted.");
} // handleFileReadAbort

function handleFileReadError(evt) {
  var message;
  switch ( {
    case "NotFoundError":
      alert("The file could not be found at the time the read was processed.");
    case "SecurityError":
      message = "<p>A file security error occured. This can be due to:</p>";
      message += "<ul><li>Accessing certain files deemed unsafe for Web applications.</li>";
      message += "<li>Performing too many read calls on file resources.</li>";
      message += "<li>The file has changed on disk since the user selected it.</li></ul>";
    case "NotReadableError":
      alert("The file cannot be read. This can occur if the file is open in another application.");
    case "EncodingError":
      alert("The length of the data URL for the file is too long.");
      alert("File error code " +;
  } // switch
} // handleFileReadError

function startFileRead(fileObject) {
  var reader = new FileReader();
  // Set up asynchronous handlers for file-read-success, file-read-abort, and file-read-errors:
  reader.onloadend = displayFileText; // "onloadend" fires when the file contents have been successfully loaded into memory.
  reader.abort = handleFileReadAbort; // "abort" files on abort.
  reader.onerror = handleFileReadError; // "onerror" fires if something goes awry.

  if (fileObject) { // Safety first.
    reader.readAsText(fileObject); // Asynchronously start a file read thread. Other supported read methods include readAsArrayBuffer() and readAsDataURL().
} // startFileRead

function handleFileSelection(evt) {
  evt.stopPropagation(); // Do not allow the drop event to bubble.
  evt.preventDefault(); // Prevent default drop event behavior.

  var files = evt.dataTransfer.files; // Grab the list of files dragged to the drop box.

  if (!files) {
    alert("<p>At least one selected file is invalid - do not select any folders.</p><p>Please reselect and try again.</p>");

  // "files" is a FileList of file objects. Try to display the contents of each file:
  for (var i = 0, file; file = files[i]; i++) {
    if (!file) {
      alert("Unable to access " +;
      continue; // Immediately move to the next file object.
    if (file.size == 0) {
      alert("Skipping " + + " because it is empty.");
    if (!file.type.match('text/.*')) {
      alert("Skipping " + + " because it is not a known text file type.");
    startFileRead(file); // Asychronously fire off a file read request.
  } // for
} // handleFileSelection