Skip to content
fileon
Get started
fileonFormatsDocsGitHub

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.

Read the docs
npm i fileon
v1.2.0

sample.pdfPDF, from its first bytes

The first 64 bytes of the file. Each block rises with its value.

00000000255044462D312E340A312030206F626A%PDF-1.4.1 0 obj
000000100A3C3C202F54797065202F436174616C.<< /Type /Catal
000000206F67202F506167657320322030205220og /Pages 2 0 R
000000303E3E0A656E646F626A0A322030206F62>>.endobj.2 0 ob

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.

FormatExtensionsFirst bytesRendered byFidelity
Images
pngjpggifwebpavifsvgbmpicotiff
89 50 4E 47Native decoding, with zoom and panexact
PDF
pdf
25 50 44 46pdf.js, rendered one page at a timeexact
Word
docxdocm
50 4B 03 04mammoth, mapped to semantic HTMLapproximate
Legacy Word
doc
D0 CF 11 E0Built-in OLE2 reader, no dependencytext only
PowerPoint
pptxpptm
50 4B 03 04Built-in OOXML readercontent only
Spreadsheets
xlsxxlsm
50 4B 03 04Built-in OpenXML parservalues
Legacy sheets
xlsods
D0 CF 11 E0SheetJS, supplied by youopt-in
Delimited text
csvtsv
No signature, read by nameBuilt-in RFC 4180 parserexact
Markdown
mdmarkdownmdx
No signature, read by namemarked, sanitised with DOMPurifyrendered
Code
tsjspygorsjavasqlyaml+40 more
No signature, read by namehighlight.jshighlighted
Structured data
jsonjsonlgeojson
No signature, read by nameBuilt-in, pretty-printedexact
Video
mp4webmmovogv
·· ·· ·· ·· 66 74 79 70Native player, streamed not bufferedexact
Audio
mp3wavoggm4aflacopus
49 44 33Native playerexact
Archives
zipjar
50 4B 03 04JSZip, listed not extractedfile listing
Fonts
woffwoff2ttfotf
77 4F 46 32FontFace, shown as a live specimenspecimen

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.

Event log
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.

index.html
<script type="module">
  import 'fileon';
</script>

<file-preview src="/files/report.pdf"></file-preview>
app.js
import { openPreview } from 'fileon';

input.addEventListener('change', () =>
  openPreview([...input.files]));
Drop to preview