Renderers are the display layer of foliate-js. They are custom HTML elements (web components) that know how to take a book object, load its sections into iframes, paginate or scroll the content, and report back the current reading position. There are two renderers: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-paginator for reflowable text (most EPUBs, MOBI, FictionBook), and foliate-fxl for fixed-layout content (pre-paginated EPUBs, CBZ comic books, and PDFs). You rarely need to instantiate them directly — view.js selects and manages the correct renderer automatically based on book.rendition?.layout.
The <foliate-view> element
view.js exports a <foliate-view> custom element that acts as the main entry point for the library. It selects the appropriate renderer, wires up progress tracking and annotation overlays, and re-exports renderer events.
view.open() is called with a book whose rendition.layout is "pre-paginated", it imports fixed-layout.js and creates a foliate-fxl element. Otherwise it imports paginator.js and creates a foliate-paginator element.
Both renderer modules register their custom elements as a side effect of being imported. You do not need to call
customElements.define() yourself.The renderer interface
Both renderers implement the same core interface:Accepts a book object (see The book interface) and prepares the renderer to display it. In
foliate-paginator, this stores the sections array and attaches a CSS transform listener to book.transformTarget for stylesheet processing.goTo(destination)
(destination: { index: number, anchor?: (doc: Document) => Element | Range }) => Promise<void>
Navigates to a destination object with the same shape returned by
book.resolveHref() or book.resolveCFI(). The anchor function, if provided, is called with the loaded Document and returns the element or range to scroll into view.Goes to the previous page or section. In scrolled mode,
distance specifies the pixel amount to scroll; in paginated mode it is ignored and the renderer moves back by one page.Goes to the next page or section. Behavior for
distance mirrors .prev().Returns an array of the currently rendered frames. In
foliate-paginator this is always at most one item (the current section). In foliate-fxl, spread views can have two items (left and right pages). Each item has:doc— theDocumentinside the iframeindex— the section indexoverlayer— theOverlayerinstance managing annotation highlights for this frame
Renderer events
Both renderers dispatch custom events that bubble up through<foliate-view>:
Fired when a section finishes loading.
event.detail contains:Fired whenever the visible location changes — on page turn, scroll, or section load.
event.detail contains:When accessed through <foliate-view>, the relocate event detail is enriched with cfi, tocItem, pageItem, and overall book fraction from progress.js.Fired when a new iframe is ready to receive an annotation overlay.
event.detail contains:CSS customization
The filter part
Both renderers expose a CSS part named filter on the iframe element. This lets you apply visual effects — such as color inversion for dark mode — to the book content without affecting overlaid elements like annotation highlights:
The paginator (foliate-paginator)
foliate-paginator handles reflowable content using CSS multi-column layout. It supports both paginated and scrolled display modes and can switch between them without reloading the section.
Layout attributes
Configure the paginator by calling.setAttribute() on the element. There is no JavaScript property API for these settings.
| Attribute | Type | Default | Description |
|---|---|---|---|
flow | "paginated" | "scrolled" | "paginated" | Display mode. "scrolled" enables continuous vertical (or horizontal for vertical writing) scrolling. |
gap | CSS <percentage> | 7% | Column gap size relative to the page width. |
margin | CSS px length | 48px | Height reserved for the header and footer regions. |
max-inline-size | CSS px length | 720px | Maximum column width in paginated mode, or maximum text width in scrolled mode. |
max-block-size | CSS px length | 1440px | Maximum height of the content area. |
max-column-count | integer | 2 | Maximum number of columns. Has no effect in scrolled mode or when the element is in portrait orientation. |
animated | boolean attribute | absent | When present, enables a sliding transition effect when turning pages. |
Running heads and footers
In paginated (non-scrolled) mode, the paginator creates header and footer regions for each column. These are accessible via.heads and .feet on the renderer instance:
.heads and .feet are null when the paginator is in scrolled mode. Check before accessing them.::part(head) and ::part(foot) pseudo-elements:
The fixed-layout renderer (foliate-fxl)
foliate-fxl handles pre-paginated content where each page has fixed dimensions. It respects pageSpread properties on sections to assemble left/right spread pairs and scales pages to fit the available space.
Zoom
The fixed-layout renderer observes azoom attribute:
Spread behavior
The renderer readsbook.rendition.spread to determine how to pair pages into spreads:
"none"— each section is displayed centered, never paired"both"— always show a two-page spread"portrait"— show spreads in landscape orientation, single pages in portrait
.prev() / .next() steps between the left and right pages before moving to the next spread.