EPUB to HTML: recover the chapters in their actual reading order

If extracted EPUB chapters appear out of order, follow the package's spine instead of sorting filenames. Work from a copy and locate its package document through META-INF/container.xml. The package connects the reading sequence to the actual chapter files; alphabetical order can put the ending before the introduction. EPUB 3.3 specification

Consider an original community-garden handbook with a welcome, a watering chapter, and winter closing instructions. The EPUB opens correctly in a reading app, but its files are named welcome.xhtml, care.xhtml, and closing.xhtml. A website assembled alphabetically would begin with care and end with the welcome.

Choose between extracting the source and converting a copy

Use extraction when you need the book's existing chapters, links, and resources with their structure intact. An EPUB archive already contains web content, so extracting it avoids an unnecessary intermediate document format.

A conversion tool can help when you want a transformed web edition instead. calibre's ebook-convert chooses output format from the output filename; its documentation lists HTML and HTMLZ output options. Ask the installed converter for help with the exact input and output pair before choosing conversion settings. Conversion can change structure and styles, so retain the source EPUB and compare the result with it. calibre conversion command

For the handbook, extracting its three existing prose chapters is the simpler starting point. Work only with material you have permission to republish. An encrypted publication may not provide readable chapter content through ordinary extraction; these steps do not remove access controls.

Find the package rather than guessing its folder

Open a duplicate EPUB with an archive utility, or rename that duplicate to .zip if the utility requires it. Extract it to a new folder. Keep the relative arrangement of chapter, image, and stylesheet folders.

Read META-INF/container.xml. Its rootfile identifies the package document with a full-path, for example:

<rootfile full-path="EPUB/package.opf"
  media-type="application/oebps-package+xml" />

That is an illustrative entry, not a required folder name. A different book can keep its package somewhere else. Open the file named by its own container entry.

The package's manifest maps item IDs to resource paths. Its spine then refers to those IDs in default reading order. Paths in this example resolve relative to EPUB/package.opf:

<manifest xmlns="http://www.idpf.org/2007/opf">
  <item id="welcome" href="text/welcome.xhtml"
    media-type="application/xhtml+xml" />
  <item id="care" href="text/care.xhtml"
    media-type="application/xhtml+xml" />
  <item id="closing" href="text/closing.xhtml"
    media-type="application/xhtml+xml" />
</manifest>
<spine xmlns="http://www.idpf.org/2007/opf">
  <itemref idref="welcome" />
  <itemref idref="care" />
  <itemref idref="closing" />
</spine>

The intended sequence is welcome, care, closing. The manifest alone is an inventory, not the chapter sequence. Also distinguish the navigation document from the prose: it supplies the book's table of contents and may include links beyond the main reading sequence. A spine entry marked linear="no" identifies auxiliary content rather than an ordinary stop in continuous reading.

First open the extracted chapter documents and inspect the text, images, and styles. For a public website, prepare ordinary web pages with a document title, language, character encoding, viewport settings, and navigation between chapters. Retain the source XHTML as your reference while adapting each page.

Do not rename every .xhtml file immediately. A link such as care.xhtml#watering will break if its destination becomes care.html without updating the link. Stylesheet URLs and image paths have the same dependency on their location.

For the garden handbook, a useful first web edition has three chapter pages and one contents page. The care chapter links directly to the closing chapter's winter checklist. Check that link before combining anything into one long page.

Combining chapters requires another pass. Two chapters may both have an element with id="notes"; those IDs collide in a single document. Give each destination a unique ID and update the corresponding fragment links. Merge the chapter bodies into one valid document instead of concatenating several complete <html> documents.

Compare the web edition with the reading app

Read the welcome, then care, then closing in both versions. Confirm that the winter checklist remains after the watering instructions and that chapter navigation follows that sequence. Inspect images with captions, footnotes with return links, and headings that now appear in the website's contents page.

An EPUB reader can also supply behavior a plain website does not reproduce, including synchronized narration or fixed-layout presentation. Treat those features as separate adaptation work. A successful text extraction does not demonstrate that the whole reading experience survived.

Open the web edition at phone width, enlarge the text, and follow the chapter and note links. Keep its asset folders with the pages when moving it to a web host. If you are making an EPUB from maintained website prose instead, the HTML-to-EPUB guide covers that opposite direction.

For this handbook, finish by following the winter checklist link from the watering chapter. The web edition is ready for review when that route reaches the right instructions, with the accompanying image and the way back still intact.

Keep reading