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 lightweight, dependency-free library that brings e-book rendering to any web application. It supports the most common e-book formats through a clean, modular API built on native ES modules — import only what you need.

Quickstart

Get a working e-book viewer running in minutes with the <foliate-view> web component.

Security

Learn how to safely render untrusted e-book content using Content Security Policy.

Core Concepts

Understand the book interface, renderer architecture, and EPUB CFI navigation.

API Reference

Explore the full API for the View element, book parsers, and utility modules.

Why foliate-js?

foliate-js powers the Foliate e-book reader app. It was designed to be small, modular, and not require any build steps — you can import the ES modules directly.

Multi-format

EPUB, MOBI, KF8 (AZW3), FB2, CBZ, and experimental PDF support out of the box.

No dependencies

Pure JavaScript with zero hard dependencies. Zip and compression libraries are optional and vendored.

Modular

Each module is standalone. Use only the parsers and renderers your project needs.

Web Components

The main entry point is a native custom element (<foliate-view>) — no framework required.

Annotations

SVG-based overlay system for highlights, underlines, and custom annotation styles.

Full-text search

Built-in search across all sections using Intl.Collator and Intl.Segmenter.

Getting started

1

Clone or submodule the repository

Since there is no stable release yet, add foliate-js as a git submodule so you can track updates.
git submodule add https://github.com/johnfactotum/foliate-js
2

Import the view module

Import view.js to register the <foliate-view> custom element.
import './foliate-js/view.js'
3

Add the element to your page

Create the element, append it to the DOM, and open a book file.
const view = document.createElement('foliate-view')
document.body.append(view)

await view.open('example.epub')
4

Listen for navigation events

Subscribe to the relocate event to track the reader’s current position.
view.addEventListener('relocate', e => {
  const { cfi, fraction, tocItem } = e.detail
  console.log(`At ${Math.round(fraction * 100)}% — ${tocItem?.label}`)
})

Supported formats

FormatModuleNotes
EPUB 2 & 3epub.jsFull support including media overlays
MOBImobi.jsDecompresses all text at once
KF8 / AZW3mobi.jsLazy decompression for performance
FictionBook 2 (FB2)fb2.jsIncluding .fb2.zip archives
Comic Book Archive (CBZ)comic-book.jsFixed-layout rendering
PDFpdf.jsExperimental; requires PDF.js
foliate-js is not yet stable. The API may change at any time. It is recommended to pin to a specific commit using a git submodule.

Build docs developers (and LLMs) love