MDN self-hosted library · e01.org
File API / notebook

File API

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

html
<input type="file" />
<div class="output"></div>
css
.output {
  overflow: scroll;
  margin: 1rem 0;
  height: 200px;
}
js
const fileInput = document.querySelector("input[type=file]");
const output = document.querySelector(".output");

fileInput.addEventListener("change", async () => {
  const [file] = fileInput.files;

  if (file) {
    output.innerText = await file.text();
  }
});