Pen Settings

HTML

CSS

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

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

Auto Save

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

              
                <!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>File Upload Form</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Baloo+Bhai+2:wght@400&display=swap" />
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
  <link rel="stylesheet" href="style.css">
</head>

<body>
  <form class="upload-wrapper">
    <h2>Upload Files</h2>
    <p>Click or drop & drop below to upload the files</p>
    <div class="upload-zone">
      <div class="icon bi bi-cloud-upload"></div>
      <p class="file-name">No File Uploaded</p>
      <p class="file-size">0.00 KB</p>
      <input type="file" id="input-file" name="file" accept="image/*" required>
    </div>
    <div class="action-btns">
      <button type="reset" id="reset-btn">Cancel</button>
      <button type="submit" id="convert-btn">Convert</button>
    </div>
  </form>
  <script src="script.js"></script>

</body>

</html>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  display: flex;
  min-height: 100vh;
  align-items: center;
  background: #f1f1f1;
  justify-content: center;
  font-family: 'Baloo Bhai 2';
}

.upload-wrapper {
  display: grid;
  width: 500px;
  height: 400px;
  padding: 20px;
  border-radius: 15px;
  background-color: white;
  grid-template-rows: auto auto 1fr auto;
  box-shadow: 0px 0px 10px 1px rgba(0, 0, 0, 0.256);
}

.upload-zone {
  width: 100%;
  display: grid;
  margin: 15px 0;
  cursor: pointer;
  position: relative;
  text-align: center;
  border-radius: 10px;
  justify-items: center;
  align-content: center;
  border: 1.6px dashed #00000070;
}

#input-file {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  right: 0;
  cursor: pointer;
  opacity: 0;
}

.bi-cloud-upload {
  line-height: 1;
  font-size: 50px;
}

.action-btns {
  display: flex;
  gap: 20px;
}

button {
  flex-grow: 1;
  border: none;
  padding: 8px;
  font-size: 15px;
  cursor: pointer;
  font-weight: 600;
  border-radius: 10px;
  letter-spacing: .8px;
  font-family: 'Baloo Bhai 2';
  background-color: rgb(211, 211, 211);
}

#reset-btn:hover {
  background-color: rgb(195, 195, 195);
}

#convert-btn {
  background-color: rgb(215, 106, 28);
  color: white;
}

#convert-btn:hover {
  background-color: rgb(234, 123, 43);
}

.is-dragging {
  border: 2px dashed rgb(255, 170, 11);
  background-color: rgba(255, 166, 0, 0.163);
}
              
            
!

JS

              
                const uploadBox = document.querySelector('.upload-wrapper')
const uploadZone = document.querySelector('.upload-zone');
const resetBtn = document.querySelector('#reset-btn');
const inputFile = document.querySelector('#input-file');
const fileName = document.querySelector('.file-name');
const fileSize = document.querySelector('.file-size');

const handleOnChange = (file) => {
  fileName.textContent = file.name;
  fileSize.textContent = (file.size / 1024).toFixed(2) + "KB"
}

inputFile.addEventListener("change", (e) => handleOnChange(e.target.files[0]))
uploadBox.addEventListener("submit", (e) => e.preventDefault())

uploadBox.addEventListener("reset", () => {
  fileName.textContent = "No File Uploaded";
  fileSize.textContent = "0.00 KB"
})

uploadZone.addEventListener('dragenter', () => uploadZone.classList.add('is-dragging'));
uploadZone.addEventListener('dragover', (e) => e.preventDefault());
uploadZone.addEventListener('dragleave', (e) => {
  if (!uploadZone.contains(e.relatedTarget)) {
    uploadZone.classList.remove('is-dragging');
  }
});

uploadZone.addEventListener("drop", (e) => {
  e.preventDefault()
  uploadZone.classList.remove('is-dragging')
  handleOnChange(e.dataTransfer.files[0])
})
              
            
!
999px

Console