2026-11-20 · 8 min. lezen
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:
mimetype— one line of text, the very first entry in the archive, stored uncompressed. The file's identity card.META-INF/container.xml— a tiny pointer: "the package document lives over there."- The package document — the
.opffile: the book's metadata, its manifest of every file, and the spine that defines reading order. - Navigation documents —
nav.xhtmland/ortoc.ncx: the table of contents your reader displays in its chapter menu. - 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
- Make a copy of the book, and work only on the copy.
- Rename it from
.epubto.zip. The extension is a costume; the bytes underneath are a standard ZIP. - Extract it with any archive tool.
- Look around. You will see
mimetype, aMETA-INFfolder, and a content folder — often namedOEBPSorEPUB. - Open the
.opfin 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.