foliate-js is a modular, dependency-free library that lets you render e-books directly in the browser. It powers the Foliate desktop e-book reader app and is designed for developers who need reliable multi-format rendering without a bundler, framework, or npm package. You import the ES modules you need, serve them from a web server, and the library handles the rest.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/johnfactotum/foliate-js/llms.txt
Use this file to discover all available pages before exploring further.
Project status
The library works well enough to have shipped in several stable releases of Foliate, but the library itself is not yet stable. The API can change at any time. There is no npm release. The recommended way to use foliate-js is to add it as a git submodule so you can track upstream changes and pin to a specific commit.Expect breaking changes. Pin to a specific commit and review the changelog before updating.
Module overview
foliate-js is organized into three categories of modules. They are designed to be independent of one another — each depends on a documented interface rather than on other modules directly. The exception isview.js, which acts as the main entry point and wires everything together.
Book parsers
These modules parse a specific file format and return an object that implements the book interface:| Module | Format |
|---|---|
epub.js + epubcfi.js | EPUB 2 and EPUB 3 |
mobi.js | Mobipocket (MOBI) and KF8/AZW3 |
fb2.js | FictionBook 2 (FB2 and FBZ) |
comic-book.js | Comic Book Archive (CBZ) |
pdf.js | PDF (experimental; requires PDF.js) |
Renderers
These modules handle pagination and layout as custom elements (web components):| Module | Use |
|---|---|
paginator.js | Reflowable books (most EPUBs, MOBI, FB2) |
fixed-layout.js | Fixed-layout EPUBs, CBZ, and PDF |
Auxiliary modules
These modules add optional functionality on top of the book and renderer interfaces:| Module | Functionality |
|---|---|
overlayer.js | SVG-based annotation overlays (highlights, underlines) |
progress.js | Reading progress tracking against TOC and page list |
search.js | Full-text search across sections |
tts.js | Text-to-speech via SSML output |
dict.js | StarDict and dictd offline dictionary lookup |
opds.js | OPDS catalog client (1.x and 2.0) |
quote-image.js | Generate shareable quote images (<foliate-quoteimage>) |
The main entry point
view.js is the highest-level module. It exports the View class and registers the <foliate-view> custom element. When you call view.open(), it detects the file format automatically, creates the correct book parser and renderer, and manages navigation, annotations, and search on your behalf. For most use cases, view.js is the only import you need.
Quickstart
Get a working e-book viewer running in minutes with the
<foliate-view> web component.API reference
Explore the full API for the View element, book parsers, and auxiliary modules.
Supported browsers
foliate-js targets the latest versions of WebKitGTK, Firefox, and Chromium. Older browsers, including Firefox ESR, are not supported. The library uses native ES modules, so files must be served from a web server — opening HTML files directly viafile:// URLs will not work.