<input type="file" />
<div class="output"></div>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.
.output {
overflow: scroll;
margin: 1rem 0;
height: 200px;
}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();
}
});