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

+ 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.


                <h1>HTML5 File Drag &amp; Drop API</h1>

<form id="upload" action="index.html" method="POST" enctype="multipart/form-data">

    <legend>HTML File Upload</legend>

    <input type="hidden" id="MAX_FILE_SIZE" name="MAX_FILE_SIZE" value="300000" />

      <label for="fileselect">Files to upload:</label>
      <input type="file" id="fileselect" name="fileselect[]" multiple="multiple" />
      <div id="filedrag">or drop files here</div>

    <div id="submitbutton">
      <button type="submit">Upload Files</button>



<div id="messages">
  <p>Status Messages</p>

<p>This code can be <a href="">downloaded and used</a> without any restrictions but please don't expect support! A link back to is appreciated.</p>


Styles for HTML5 File Drag & Drop demonstration
Featured on
Developed by Craig Buckler (@craigbuckler) of

body {
  font-family: "Segoe UI", Tahoma, Helvetica, freesans, sans-serif;
  font-size: 90%;
  margin: 10px;
  color: #333;
  background-color: #fff;

h2 {
  font-size: 1.5em;
  font-weight: normal;

h2 {
  font-size: 1.3em;

legend {
  font-weight: bold;
  color: #333;

#filedrag {
  display: none;
  font-weight: bold;
  text-align: center;
  padding: 1em 0;
  margin: 1em 0;
  color: #555;
  border: 2px dashed #555;
  border-radius: 7px;
  cursor: default;

#filedrag.hover {
  color: #f00;
  border-color: #f00;
  border-style: solid;
  box-shadow: inset 0 3px 4px #888;

img {
  max-width: 100%;

pre {
  width: 95%;
  height: 8em;
  font-family: monospace;
  font-size: 0.9em;
  padding: 1px 2px;
  margin: 0 0 1em auto;
  border: 1px inset #666;
  background-color: #eee;
  overflow: auto;

#messages {
  padding: 0 10px;
  margin: 1em 0;
  border: 1px solid #999;

#progress p {
  display: block;
  width: 240px;
  padding: 2px 5px;
  margin: 2px 0;
  border: 1px inset #446;
  border-radius: 5px;
  background: #eee url("progress.png") 100% 0 repeat-y;

#progress p.success {
  background: #0c0 none 0 0 no-repeat;

#progress p.failed {
  background: #c00 none 0 0 no-repeat;


filedrag.js - HTML5 File Drag & Drop demonstration
Featured on
Developed by Craig Buckler (@craigbuckler) of
(function() {

  // getElementById
  function $id(id) {
    return document.getElementById(id);

  // output information
  function Output(msg) {
    var m = $id("messages");
    m.innerHTML = msg + m.innerHTML;

  // file drag hover
  function FileDragHover(e) {
    e.preventDefault(); = (e.type == "dragover" ? "hover" : "");

  // file selection
  function FileSelectHandler(e) {

    // cancel event and hover styling

    // fetch FileList object
    var files = || e.dataTransfer.files;

    // process all File objects
    for (var i = 0, f; f = files[i]; i++) {


  // output file information
  function ParseFile(file) {

    Output("<p>File information: <strong>" + + "</strong> type: <strong>" + file.type + "</strong> size: <strong>" + file.size + "</strong> bytes</p>");


  // initialize
  function Init() {

    var fileselect = $id("fileselect"),
      filedrag = $id("filedrag"),
      submitbutton = $id("submitbutton");

    // file select
    fileselect.addEventListener("change", FileSelectHandler, false);

    // is XHR2 available?
    var xhr = new XMLHttpRequest();
    if (xhr.upload) {

      // file drop
      filedrag.addEventListener("dragover", FileDragHover, false);
      filedrag.addEventListener("dragleave", FileDragHover, false);
      filedrag.addEventListener("drop", FileSelectHandler, false); = "block";

      // remove submit button = "none";


  // call initialization file
  if (window.File && window.FileList && window.FileReader) {