Preview any file, right where it lives
Preview any file, right where it lives.
One custom element renders PDFs, Office documents, spreadsheets, images, video, code and archives in the browser. No upload, no server, no framework.
npm i fileonsample.pdfPDF, from its first bytes
The first 64 bytes of the file. Each block rises with its value.
Or open a sample. Drop a file anywhere to inspect your own.
The same component, inline
Embedded in the page instead of a modal. The toolbar follows the viewer: pages for a PDF, sheet tabs for a workbook, zoom for an image. Each viewer arrives the first time a file needs it.
What it reads
Type is decided by a file's first bytes, then its extension, then the server'sContent-Type. A PNG named .txt still renders as an image, and anything unrecognised gets a download card instead of a broken view.
| Format | Extensions | First bytes | Rendered by | Fidelity |
|---|---|---|---|---|
| Images | pngjpggifwebpavifsvgbmpicotiff | 89 50 4E 47 | Native decoding, with zoom and pan | exact |
pdf | 25 50 44 46 | pdf.js, rendered one page at a time | exact | |
| Word | docxdocm | 50 4B 03 04 | mammoth, mapped to semantic HTML | approximate |
| Legacy Word | doc | D0 CF 11 E0 | Built-in OLE2 reader, no dependency | text only |
| PowerPoint | pptxpptm | 50 4B 03 04 | Built-in OOXML reader | content only |
| Spreadsheets | xlsxxlsm | 50 4B 03 04 | Built-in OpenXML parser | values |
| Legacy sheets | xlsods | D0 CF 11 E0 | SheetJS, supplied by you | opt-in |
| Delimited text | csvtsv | No signature, read by name | Built-in RFC 4180 parser | exact |
| Markdown | mdmarkdownmdx | No signature, read by name | marked, sanitised with DOMPurify | rendered |
| Code | tsjspygorsjavasqlyaml+40 more | No signature, read by name | highlight.js | highlighted |
| Structured data | jsonjsonlgeojson | No signature, read by name | Built-in, pretty-printed | exact |
| Video | mp4webmmovogv | ·· ·· ·· ·· 66 74 79 70 | Native player, streamed not buffered | exact |
| Audio | mp3wavoggm4aflacopus | 49 44 33 | Native player | exact |
| Archives | zipjar | 50 4B 03 04 | JSZip, listed not extracted | file listing |
| Fonts | woffwoff2ttfotf | 77 4F 46 32 | FontFace, shown as a live specimen | specimen |
Exact means pixel-accurate. Text only means the words and tables survive but the formatting does not. Office files at a public URL can also be handed to the Microsoft viewer from the toolbar for a full-fidelity render.
When things go wrong
A preview component spends much of its life handling files that are missing, corrupt, blocked or mislabelled. These all fail on purpose — open them and watch what the reader is told, and what the event log records.
Waiting for events…
Read the docs
Every option, event and error code, with the snippet you need next to it.
Two lines to your first preview.
Import it once, then use the element in any template, or open the full-screen viewer from code. React, Vue, Svelte and Angular need no wrapper.
<script type="module">
import 'fileon';
</script>
<file-preview src="/files/report.pdf"></file-preview>import { openPreview } from 'fileon';
input.addEventListener('change', () =>
openPreview([...input.files]));