iloveepub
選單
ZH-TW

2026-11-20 · 8 分鐘閱讀

Inside an EPUB File: Container, OPF, Navigation and XHTML Explained

An EPUB is a ZIP archive of web pages plus a few bookkeeping files. Here is what each piece — mimetype, container.xml, the OPF, nav documents, XHTML chapters — actually does, and what breaks when it fails.

EPUBFile FormatXHTML


Most of the mystery around ebooks dissolves in five minutes, with one file and no tools: an EPUB is a ZIP archive full of ordinary web pages, plus three small files that do the bookkeeping. That is not a simplification — it is the actual design. Rename any .epub to .zip and your operating system will open it like any other archive. What spills out is a small website: chapters as HTML documents, stylesheets, images, sometimes fonts — and a handful of pointer files whose job is to hold it all together.

Everything else about EPUB follows from that architecture. Why the text reflows to any screen. Why books break in the same few places, over and over. Why a web browser, with nothing installed, can open, render and edit one. Why EPUB tools can run entirely on your own device with nothing uploaded. This is the guided tour: each piece of the package, what it does, and what happens to the book when it fails.

The short answer

Unzipped, an EPUB is a small website with a manifest. The pieces, in the order a reader meets them:

  1. mimetype — one line of text, the very first entry in the archive, stored uncompressed. The file's identity card.
  2. META-INF/container.xml — a tiny pointer: "the package document lives over there."
  3. The package document — the .opf file: the book's metadata, its manifest of every file, and the spine that defines reading order.
  4. Navigation documents — nav.xhtml and/or toc.ncx: the table of contents your reader displays in its chapter menu.
  5. The content — XHTML chapters, CSS, images, embedded fonts. The book itself.

Readers validate their way down this list, and each layer failing produces a different, recognizable symptom. Knowing the anatomy is the fastest troubleshooting skill in ebooks.

Open one yourself

  1. Make a copy of the book, and work only on the copy.
  2. Rename it from .epub to .zip. The extension is a costume; the bytes underneath are a standard ZIP.
  3. Extract it with any archive tool.
  4. Look around. You will see mimetype, a META-INF folder, and a content folder — often named OEBPS or EPUB.
  5. Open the .opf in a text editor, then a chapter .xhtml. Both are plain, human-readable text — you are now reading the book's plumbing.

One warning, and it matters: the way back is where books break. Re-zipping an unpacked EPUB with a regular archiver compresses and reorders entries, trampling rules the format insists on — the most common way people damage a book while trying to inspect it. Treat the unpacked copy as a dissection specimen. When you want to look inside or change a book you actually read, use tools that repack correctly: the EPUB editor opens the book and shows chapters, stylesheets and metadata as editable text, then exports a standards-compliant EPUB; the browser reader renders the book without unpacking anything. Both do their work in the page itself — the file never leaves your device.

The mimetype: one line, one strict rule

The first file in the archive contains a single line: application/epub+zip. That is the entire file. The strict part is the packaging: the EPUB specification requires this entry to be the first in the ZIP, stored uncompressed, with nothing added around it.

The point is cheap identification. With those bytes sitting at a known position in a known state, any program can recognize an EPUB by sniffing the start of the file — no unpacking, no parsing. File managers, mail filters and reading apps all lean on it for exactly this.

What breaks: repackaging tools that compress the entry, or file it somewhere other than first. Readers check the mimetype before reading anything else, and a wrong one can get the entire book refused — the most common packaging defect there is, and maddening from the outside, because every chapter sits inside, unharmed. The repair is mechanical: restore the entry to its required position and the book opens again.

META-INF/container.xml: the shipping label

The next stop is a few lines of XML whose entire job is to point at the package document: essentially "the rootfile is at OEBPS/content.opf."

Why the indirection? Because the spec does not fix the package document's name or location. Publishers nest it in OEBPS, EPUB, or a folder of their own naming, and call it content.opf, package.opf, or something less predictable. With the archive layout free-form, there has to be exactly one mandated place to look for the pointer — and that place is META-INF/container.xml.

What breaks: a missing or malformed container file, and the reader cannot find the book inside its own archive. From the outside it looks identical to a mimetype failure — "not a valid EPUB" — and the fix is equally mechanical: rebuild the pointer.

The package document: the brain

One file, three jobs. The .opf is where a book describes itself, inventories itself, and orders itself.

The metadata section carries Dublin Core elements — the same standard libraries use — with dc:title, dc:creator, dc:language and dc:identifier at the core. Everything your reader displays about the book, from the shelf card to the sort order to which dictionary pops up on a long-press, is built from this block. It is small, plain XML — which is why a mislabeled book is a one-minute edit rather than a re-download. The field-by-field story, including the messy reality of series information, is its own article.

The manifest is the inventory: every chapter, stylesheet, image, font and navigation file in the book, each declared with its media type. The reader's contract is with the manifest — a file that sits in the archive but is never declared effectively does not exist as far as the book is concerned. This is also how EPUB tools know what to keep, check or strip when they rebuild a book: they read the same inventory.

The spine is the reading order: a linear list of manifest items saying what follows what. It has to exist, because files have no inherent order — chapter3.xhtml sorting before chapter4.xhtml is a naming convention, nothing more. The spine is the authority. Its separation from the file list explains things you have seen as a reader: bonus material can ship inside the archive without ever appearing in the reading flow, and a scrambled spine delivers a book whose chapters are all fine and whose order is wrong.

What breaks here: manifest entries pointing at files that are not there, spine items that were never declared, missing required metadata. All of it is machine-checkable and machine-repairable — this is the layer structural repairs rebuild.

Navigation: two tables of contents, for historical reasons

EPUB's history left the format with two TOC documents. EPUB 2 defined the table of contents in toc.ncx — an XML format inherited from an older ebook standard. EPUB 3 replaced it with nav.xhtml: the TOC as an ordinary HTML page, listed in the manifest with a marker that says "this is the navigation." EPUB 3 books commonly carry both, because older readers only understand the NCX and dropping it would strand them.

Your reader's chapter menu — the list you open to jump between chapters — is built from these documents. Two things follow. First, a book with an empty or dead-link nav document has a broken chapter menu while every word of text is intact: the text and its map are separate files, and only one of them is broken. Second, the print-style "Contents" page you sometimes see inside a book is just an ordinary chapter; the navigational TOC and the visible contents page are different things that happen to agree.

What breaks: hand editing and format conversion, mostly — anchors pointing at files someone deleted, an empty nav, an NCX a converter silently mangled. The robust fix rebuilds both documents from the spine rather than patching either one.

The content: XHTML, CSS, and the rest

The bulk of the archive is the book itself: chapters as XHTML documents, plus supporting files.

XHTML is HTML with XML discipline: every tag closed, everything nested properly, attribute values quoted. The strictness is not pedantry. An XHTML chapter is parsed as XML, and in XML one unclosed tag is not a rendering quirk — it is a parse error that can blank the chapter. Readers that accept sloppy chapters are being forgiving, not correct.

Otherwise, these are ordinary web pages. Headings, paragraphs and emphasis; links to other chapters and to anchors inside them; images referenced by relative path; footnotes as linked text. One or two CSS stylesheets set the typography for the whole book, and @font-face rules can pull in embedded font files. Everything referenced is declared in the manifest — a small, self-contained website.

That is the secret of reflow, too. Chapters are structured documents rather than painted pages, so the reading device decides the typography at display time: font, size, line length, margins. The same file is a large-print edition for one reader and a dense two-column view for another. And it explains how this site exists at all: an EPUB needs no server, no secret decoder, no format license — a browser already contains every ingredient for opening, rendering and editing one. That is why the reader and the editor are web pages doing the work on your machine, and why the no-upload promise is structural rather than a policy: there is nothing to send, because your own browser is the tool.

Why a normal person should care

  • Diagnosis. Every EPUB failure maps to one layer of this stack. "Won't open" means the top layers, a missing chapter menu means navigation, an ugly layout means content — the full symptom map is how to fix a broken EPUB.
  • Nothing is opaque. Every file in the package is text you can open in an editor — books stop being fragile magic objects and become organized documents.
  • Better tool choices. Knowing the layers, you can tell a tool that rebuilds packaging from one that rewrites your text — and you know why a browser-based tool can promise, structurally, that your book never leaves your device.

The bottom line

An EPUB is a website in a box, shipped with its own inventory and reading order. The mimetype identifies it, container.xml points the way, the OPF describes and orders it, the nav documents map it, and the XHTML chapters are the book. Every layer is plain text, every layer is inspectable, and every layer fails in its own characteristic way — which is exactly why every layer is fixable. Unpack one tonight, on a copy, and the format stops being magic.

免費工具,不上傳

EPUB → smaller EPUB在瀏覽器中直接透過重新編碼圖片和清除冗餘來減小 EPUB 體積。開啟工具 →EPUB + EPUB → EPUB將多本 EPUB 合併為一個帶統一目錄的檔案。開啟工具 →EPUB → EPUB × N依章節將 EPUB 分割成多本書,每個部分都完全有效。開啟工具 →EPUB → PDF將 EPUB 轉換為分頁的 PDF,用於列印或分享。開啟工具 →PDF → EPUB將 PDF 書籍轉換為可在任何閱讀器上調整字級的可重排 EPUB。開啟工具 →EPUB → KEpub在瀏覽器中將 EPUB 轉換為 Kobo 增強的 KEpub 格式。開啟工具 →EPUB → TXT將 EPUB 全文提取為乾淨的純文字檔案。開啟工具 →EPUB → Markdown將 EPUB 轉換為結構化的 Markdown 檔案,保留標題與列表。開啟工具 →TXT → EPUB把 TXT 純文字轉換成帶章節目錄的 EPUB 電子書。開啟工具 →EPUB → HTML把 EPUB 轉換為單一自包含 HTML 檔案,樣式與圖片全部內嵌。開啟工具 →DOCX → EPUB把 Word 文件轉成可重排的 EPUB 電子書——標題自動變章節。開啟工具 →EPUB → DOCX把 EPUB 電子書轉換成可編輯的 Word (.docx) 文件。開啟工具 →EPUB Reader直接在瀏覽器中開啟並閱讀 EPUB — 無需安裝。開啟工具 →EPUB → word count統計任何 EPUB 的字數、字元、章節與閱讀時間。開啟工具 →EPUB → audio用瀏覽器免費語音合成聽任何 EPUB——不上傳、不安裝。開啟工具 →Fix My EPUB診斷、修復並複檢一本壞掉的 EPUB——純瀏覽器本機完成。開啟工具 →EPUB Editor在瀏覽器中直接編輯 EPUB 內文、CSS、詮釋資料與封面。開啟工具 →EPUB → new cover用你自己的圖片替換 EPUB 封面 — 儲存前可預覽。開啟工具 →EPUB → new metadata編輯 EPUB 的書名、作者、ISBN 等詮釋資料 — 本機處理,不上傳。開啟工具 →Repair EPUB修復打不開的 EPUB 檔案 — 瀏覽器內完成容器、mimetype 與參照修復。開啟工具 →EPUB → new TOC從真實章節清單重建損壞或缺失的 EPUB 目錄。開啟工具 →EPUB → no images移除 EPUB 中的所有圖片 — 為電子墨水屏與舊裝置減負。開啟工具 →EPUB → new fonts移除 EPUB 內嵌字型或替換為自己的字型 — 檔案更小更乾淨。開啟工具 →