client-side epub 3 builder

Build EPUBs
in the browser.

No server. No backend. Pure JavaScript. Turn HTML into valid EPUB 3 files with a clean, chainable API — sanitizer, cover, TOC, images and fonts included.

Try it live View source
npm npm install epubit copy
cdn cdn.jsdelivr.net/npm/epubit/epubit.min.js copy
size 16.6 KB minified · no dependencies
Interactive

Build an EPUB right here

Fill in the fields, click generate — your browser downloads a real, valid EPUB 3 file.

Book builder
Ready — click generate to build your EPUB
Generated code
Reference

Clean, chainable API

Every method returns this for chaining. All generation methods are async.

new EBook(options)

Create a book. Pass title, author, language, publisher, description, date, uuid, rights, sanitize.

.addChapter(title, html, opts)

Add a chapter. HTML is sanitized automatically. Options: id, order, css[], raw.

.setCover(data, mime, filename, opts)

Set the cover image. Pass base64, ArrayBuffer, or Blob. opts.asPage inserts a full cover page.

.addTOCPage(opts)

Insert a human-readable contents page before chapter one. Custom title, css, inlineStyle.

.addCSS(filename, content)

Embed a stylesheet. Reference it in chapters via opts.css: ["style.css"].

.addImage(filename, data, mime)

Add an image asset. Reference in HTML as ../images/filename. Supports JPEG, PNG, WebP, GIF, SVG.

.addFont(filename, data, mime)

Embed a font file. Reference via @font-face in your CSS. Supports WOFF2, WOFF, TTF, OTF.

.updateChapter(id, title, html)

Replace a chapter's title or content in place. Throws if id is not found.

.removeChapter(id)

Remove a chapter by its id. Silent if not found.

.reorderChapters(idArray)

Re-sequence chapters by passing ids in the desired order.

.download(filename?)

Generate and trigger a browser download. Filename defaults to slugified title.

.generate() → Blob

Returns raw Blob. Also: .toBase64() for a base64 string, .toObjectURL() for a preview URL.

Why epubit.js

Everything included

One file, zero dependencies beyond JSZip, covers the full EPUB 3 spec.

🛡

Allowlist sanitizer

DOM-based HTML sanitizer preserves tables, images, links, figures, lists, code — strips scripts, iframes, forms.

📖

EPUB 3 + EPUB 2 compat

Generates nav.xhtml for EPUB 3 readers and toc.ncx for legacy EPUB 2 readers simultaneously.

🖼

Cover page

Full-bleed cover XHTML page with proper epub:type="cover" and OPF cover-image manifest property.

📑

Hard-coded TOC page

Numbered, clickable contents page inserted into the spine — the kind printed on page 3 of a real book.

🎨

Fonts & stylesheets

Embed WOFF2 fonts and CSS files. Link stylesheets per-chapter or globally across the whole book.

UMD module

Works as a plain script tag, CommonJS require(), or ESM import. Auto-injects JSZip if not present.