Convert HTML to EPUB

HTML to EPUB is one of those conversions that sounds complicated and isn't. EPUB is already HTML underneath — the container is just a zipped bundle of XHTML files with a manifest. Converting mostly means wrapping your HTML in the bundle correctly, and one command line does that. The harder part is deciding what to include and cleaning up the source before you wrap it.

Who wants HTML to EPUB, and why

  • Archivists. Save web articles for offline reading on an e-reader. Pocket and Instapaper used to do this reliably; both are worse than they used to be.
  • Writers. If you drafted in plain HTML or Markdown-rendered-to-HTML, EPUB is the shortest path to a distributable ebook.
  • Documentation maintainers. Turning a static site into a downloadable ebook. Some readers prefer EPUB over browsing docs online.
  • Anyone escaping a CMS. Export your blog's HTML, bundle as EPUB, and you have a portable backup that doesn't depend on the platform still existing.

Method 1: Pandoc (one-liner)

pandoc input.html -o output.epub \
  --metadata title="My Book" \
  --metadata author="Jane Doe" \
  --metadata lang="en-US" \
  --toc --toc-depth=2

That's the whole conversion. --toc builds the navigation document from your HTML heading structure. --toc-depth=2 includes h1 and h2 but not h3+ (tweak to taste). Pandoc inlines images that are referenced by relative path; absolute URLs need a working internet connection at conversion time.

Add a cover:

pandoc input.html -o output.epub --epub-cover-image=cover.jpg ...

Multiple HTML files? Concatenate them in reading order:

pandoc chap01.html chap02.html chap03.html -o book.epub --toc

Method 2: Calibre (GUI + recipe engine)

For single HTML files: drag the file into Calibre → Convert books → output EPUB → set metadata → OK. Done.

For whole websites, Calibre has a news recipe system designed for this:

  1. Open Calibre → Fetch newsAdd a custom news source
  2. Pick Download entire site or use a recipe from the built-in list (thousands of sites already have recipes)
  3. Run the recipe — Calibre crawls the site, extracts article content, and builds an EPUB

Good for newspaper and magazine sites. Less useful for JS-rendered single-page apps (it fetches the raw HTML, which on a modern SPA is mostly empty).

Method 3: Save a rendered page, then convert

For a JavaScript-heavy site where view-source is empty, the trick is to render first, save second:

  1. Open the page in a browser
  2. File → Save Page As → Webpage, Complete (saves HTML + images + CSS in a folder)
  3. Point Pandoc or Calibre at the saved HTML file

Reader mode (Firefox, Safari) is even cleaner — it strips nav, ads, and sidebars first. Reader mode → Save as HTML → convert. Usually the best-looking result for a single article.

Method 4: Build the EPUB by hand

If you want precise control (and don't mind a 15-minute learning curve), an EPUB is just:

mybook.epub/
├── mimetype
├── META-INF/container.xml
└── OEBPS/
    ├── content.opf
    ├── nav.xhtml
    ├── chapter1.xhtml
    ├── chapter2.xhtml
    └── images/

Zip that folder with mimetype stored (not compressed) as the first entry, rename to .epub, and you have a valid EPUB. See our create an EPUB guide for the full walkthrough. This is worth doing once to understand what the converters are hiding from you.

What goes wrong, and the fix

  • Images don't show up. The HTML references images by absolute URL but the converter ran offline, or the CDN blocks the user agent. Download images locally first and rewrite img src to relative paths.
  • CSS looks wrong. Complex layout (grid, flex, CSS variables, @media) often doesn't survive. Simplify to block-level flow before conversion, or accept the defaults.
  • No chapter breaks. You gave the converter one big HTML file with no heading structure. Add h1/h2 tags or split into multiple files.
  • Fonts missing. Web fonts loaded via @font-face or Google Fonts don't embed. Either download the font and reference it locally, or accept the reader's default font.
  • Validation errors. Dirty HTML (unclosed tags, mismatched nesting) passes in browsers but fails EPUBCheck. Run HTML through tidy or a formatter first, then convert. Verify with the EPUB validator.

After conversion

  1. Validate the EPUB. Fix anything flagged as an error. Warnings usually fine, but read them.
  2. Set metadata — title, author, language, description. Converters guess from HTML <title> and often guess wrong.
  3. Compress. HTML-sourced EPUBs often carry duplicate CSS, unreferenced images, and other leftovers.
  4. Test on a real reader. Load it on a Kindle, iBooks, or an EPUB reader before you call it done.

Related

Try it now — free

Free online EPUB checker and validator — no signup. Catch the structural, well-formedness, and reference errors that get books rejected from KDP and Apple Books.

EPUB Validator & Checker →

Found this helpful? Share it