Skip to main content

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.

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.

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 is view.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:
ModuleFormat
epub.js + epubcfi.jsEPUB 2 and EPUB 3
mobi.jsMobipocket (MOBI) and KF8/AZW3
fb2.jsFictionBook 2 (FB2 and FBZ)
comic-book.jsComic Book Archive (CBZ)
pdf.jsPDF (experimental; requires PDF.js)

Renderers

These modules handle pagination and layout as custom elements (web components):
ModuleUse
paginator.jsReflowable books (most EPUBs, MOBI, FB2)
fixed-layout.jsFixed-layout EPUBs, CBZ, and PDF

Auxiliary modules

These modules add optional functionality on top of the book and renderer interfaces:
ModuleFunctionality
overlayer.jsSVG-based annotation overlays (highlights, underlines)
progress.jsReading progress tracking against TOC and page list
search.jsFull-text search across sections
tts.jsText-to-speech via SSML output
dict.jsStarDict and dictd offline dictionary lookup
opds.jsOPDS catalog client (1.x and 2.0)
quote-image.jsGenerate 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 via file:// URLs will not work.

Build docs developers (and LLMs) love