๐Ÿ“– Chapter 90: HTML for E-Books (EPUB 3)

Building an End-to-End Published E-Book

Full-Scale Production Project: Architecting, Authoring, Validating, and Packaging a Complete Multi-Chapter Technical E-Book

LEARNING OBJECTIVES โŒต
  • Synthesize all core EPUB 3 specifications into a publication-ready, commercial-grade digital book.
  • Construct the entire container file hierarchy from mimetype to META-INF/container.xml and package.opf.
  • Author structured XHTML content documents featuring MathML formulas, pop-up footnotes, sidebars, and DPUB-ARIA landmarks.
  • Implement production-grade CSS supporting fluid reflow, dark mode safety, and pagination break controls.
  • Build a tri-part Navigation Document (nav.xhtml) with TOC, Landmarks, and Print Page-Lists.
  • Execute automated packaging and verify 100% compliance with epubcheck and Ace by DAISY.
๐ŸŽฌ INTERACTIVE VISUAL PIPELINE Core Architecture Simulation
๐ŸŒ
1. Input
Directives & Tags
โš™๏ธ
2. Parse
Tokenizer & AST
๐ŸŒณ
3. Layout
Box Model & Flow
๐ŸŽจ
4. Render
GPU Paint & Composite
PHASE 1: INPUT & DIRECTIVES
Browser receives declarative markup stream, parsing tag tokens and initializing component state.

๐Ÿ“– The Mental Model & Story (Intuitive Foundation)

Assembling an EPUB 3 publication is like crafting a mechanical Swiss chronometer. Each individual gearโ€”strict XML syntax, Dublin Core metadata, semantic DPUB-ARIA landmarks, pagination-safe CSS, uncompressed byte offsets, and navigation treesโ€”must mesh with microscopic precision.

+-----------------------------------------------------------------------------------+
|                        END-TO-END PUBLISHING PIPELINE                             |
+-----------------------------------------------------------------------------------+
  [Step 1: Scaffolding]    -> mimetype (uncompressed) + META-INF/container.xml
            |
  [Step 2: Content XHTML]  -> Strict XHTML5 + MathML + Pop-up Footnotes + ARIA Roles
            |
  [Step 3: Styling Engine] -> Fluid CSS3 + Break Controls + Dark Mode Safety
            |
  [Step 4: Navigation]     -> nav.xhtml (TOC + Landmarks + Page-List)
            |
  [Step 5: Master OPF]     -> package.opf (Metadata + Manifest + Spine)
            |
  [Step 6: Packaging & QA] -> OCF Zip -> EpubCheck Validation -> Ace DAISY Audit
            |
            v
  [DISTRIBUTION: Apple Books, Amazon Kindle KFX, Kobo, Thorium Reader]

When every piece is built according to open W3C standards, your book glides effortlessly across Apple Books on iOS, Kindle Paperwhite on E-Ink, and screen readers on Windows with flawless typographic elegance.


Technical Deep Dive & Specifications

Complete Project File Tree Architecture

Below is the production filesystem layout for our complete technical book, "Architectures of Resilient Systems":

resilient-systems-project/
โ”œโ”€โ”€ mimetype                          <- Exact 20 bytes: application/epub+zip
โ”œโ”€โ”€ META-INF/
โ”‚   โ””โ”€โ”€ container.xml                 <- Container bootstrap pointer
โ””โ”€โ”€ EPUB/
    โ”œโ”€โ”€ package.opf                   <- Master Package Document
    โ”œโ”€โ”€ text/
    โ”‚   โ”œโ”€โ”€ cover.xhtml               <- Book Cover Page
    โ”‚   โ”œโ”€โ”€ nav.xhtml                 <- Primary Navigation Document
    โ”‚   โ”œโ”€โ”€ ch01_concurrency.xhtml    <- Chapter 1 (Content + MathML + Footnotes)
    โ”‚   โ”œโ”€โ”€ ch02_consensus.xhtml      <- Chapter 2 (Content + Complex Tables)
    โ”‚   โ””โ”€โ”€ glossary.xhtml            <- Glossary of Terms
    โ”œโ”€โ”€ styles/
    โ”‚   โ””โ”€โ”€ epub.css                  <- Production Paged Media Stylesheet
    โ””โ”€โ”€ images/
        โ”œโ”€โ”€ cover.svg                 <- Vector Cover Artwork
        โ””โ”€โ”€ raft_diagram.svg          <- Accessible Architectural SVG

๐Ÿ’ป Interactive Code Playground

Let's examine the core files that make up this complete publication.

1. META-INF/container.xml


2. EPUB/package.opf (Master Control Center)


3. EPUB/text/ch01_concurrency.xhtml (Chapter 1)


4. EPUB/text/nav.xhtml (Navigation Document)


5. EPUB/styles/epub.css (Hardened Typography)


SYS: ACTIVE
HULL: 98%
CORE: STABLE
NET: ONLINE
HTML STARSHIP CODE TERMINAL playground.html
LIVE RENDER & DIAGNOSTICS CORE TEMP: 45ยฐC
INSPECTING DOM: VALID
TAGS: SCANNING...
<?xml version="1.0" encoding="UTF-8"?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
  <rootfiles>
    <rootfile full-path="EPUB/package.opf" media-type="application/oebps-package+xml"/>
  </rootfiles>
</container>
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" 
         unique-identifier="pub-id" 
         version="3.0" 
         prefix="rendition: http://www.idpf.org/vocab/rendition/# schema: http://schema.org/">

  <!-- 1. METADATA & ACCESSIBILITY -->
  <metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
    <dc:identifier id="pub-id">urn:uuid:7c8b9d0e-1f2a-3b4c-5d6e-7f8a9b0c1d2e</dc:identifier>
    <dc:title>Architectures of Resilient Systems</dc:title>
    <dc:creator id="aut">Dr. Marcus Vance</dc:creator>
    <meta refines="#aut" property="role" scheme="marc:relators">aut</meta>
    <dc:publisher>Distributed Systems Press</dc:publisher>
    <dc:language>en-US</dc:language>
    <meta property="dcterms:modified">2026-08-20T18:00:00Z</meta>

    <!-- Schema.org Accessibility Metadata -->
    <meta property="schema:accessMode">textual</meta>
    <meta property="schema:accessMode">visual</meta>
    <meta property="schema:accessModeSufficient">textual,visual</meta>
    <meta property="schema:accessibilityFeature">structuralNavigation</meta>
    <meta property="schema:accessibilityFeature">alternativeText</meta>
    <meta property="schema:accessibilityFeature">tableOfContents</meta>
    <meta property="schema:accessibilityHazard">none</meta>
    <meta property="schema:accessibilitySummary">Conforms to WCAG 2.1 AA and EPUB Accessibility 1.1.</meta>
  </metadata>

  <!-- 2. MANIFEST -->
  <manifest>
    <item id="nav" href="text/nav.xhtml" media-type="application/xhtml+xml" properties="nav" />
    <item id="cover" href="text/cover.xhtml" media-type="application/xhtml+xml" />
    <item id="ch01" href="text/ch01_concurrency.xhtml" media-type="application/xhtml+xml" properties="mathml" />
    <item id="ch02" href="text/ch02_consensus.xhtml" media-type="application/xhtml+xml" properties="svg" />
    <item id="glossary" href="text/glossary.xhtml" media-type="application/xhtml+xml" />
    <item id="css" href="styles/epub.css" media-type="text/css" />
    <item id="cover-img" href="images/cover.svg" media-type="image/svg+xml" properties="cover-image" />
    <item id="diagram-raft" href="images/raft_diagram.svg" media-type="image/svg+xml" />
  </manifest>

  <!-- 3. SPINE -->
  <spine>
    <itemref idref="cover" linear="no" />
    <itemref idref="nav" />
    <itemref idref="ch01" />
    <itemref idref="ch02" />
    <itemref idref="glossary" />
  </spine>

</package>
/* Core Layout & Hyphenation */
html, body {
  margin: 0;
  padding: 0;
  font-size: 100%;
  line-height: 1.5;
  hyphens: auto;
  -webkit-hyphens: auto;
}

/* Headings with Orphan Prevention */
h1, h2, h3 {
  line-height: 1.2;
  break-after: avoid;
  page-break-after: avoid;
}

h1 {
  font-size: 1.8rem;
  margin-top: 1.5em;
  margin-bottom: 0.8em;
  text-align: center;
  break-before: page;
  page-break-before: always;
}

p {
  margin-top: 0;
  margin-bottom: 0;
  text-indent: 1.5em;
  text-align: justify;
  orphans: 2;
  widows: 2;
}

h1 + p, h2 + p, p.lead {
  text-indent: 0;
}

/* Theme-Safe Callout Box */
aside.callout {
  margin: 1.5em 0;
  padding: 1em;
  border-left: 4px solid #0284c7;
  background-color: rgba(2, 132, 199, 0.08);
  border-radius: 0 4px 4px 0;
  break-inside: avoid;
  page-break-inside: avoid;
}

/* MathML formatting */
.math-block {
  text-align: center;
  margin: 1.5em 0;
  break-inside: avoid;
}

๐Ÿ‹๏ธ Hands-On Exercise

๐ŸŽฏ The Challenge: Author and Integrate Chapter 2

Instructions:

  1. Create EPUB/text/ch02_consensus.xhtml containing:
    • Proper XHTML prologue, namespaces (xmlns, xmlns:epub), and lang tags.
    • A chapter header for "Chapter 2: Distributed Consensus & Raft".
    • A section containing an accessible <figure> wrapping ../images/raft_diagram.svg with alt text and a <figcaption>.
  2. Connect ch02_consensus.xhtml into the package.opf <manifest> and <spine>.
  3. Update nav.xhtml to include Chapter 2 in the Table of Contents.

๐Ÿ Starter Code Sandbox

SYS: ACTIVE
HULL: 98%
CORE: STABLE
NET: ONLINE
STARTER CODE SANDBOX exercise.html
LIVE RENDER & DIAGNOSTICS CORE TEMP: 45ยฐC
INSPECTING DOM: VALID
TAGS: SCANNING...

โš ๏ธ Common Pitfalls

  1. Mismatched Manifest IDs: Declaring id="chapter-2" in <manifest> but referencing idref="ch02" in <spine>. This triggers an instant OPF-014 fatal validation failure.
  2. Forgetting to Update dcterms:modified: Every time you package a new build of an EPUB, you must update the <meta property="dcterms:modified"> timestamp to current UTC time.
  3. Unescaped Special Characters in Titles: Writing <dc:title>Design & Architecture</dc:title> in package.opf will crash XML parsers. It must be written as Design &amp; Architecture.

๐Ÿ’ก Pro Tips

  1. Automate the Build Pipeline: Write an npm run build script that runs XML linting, checks MathML validity, packages the OCF archive, and executes epubcheck and ace in a single command.
  2. Multi-Store Testing: Before commercial distribution, test your compiled .epub in:
    • Apple Books (macOS / iOS)
    • Kindle Previewer 3 (Amazon KF8 / KFX)
    • Thorium Reader (W3C Reference Desktop Reader)

๐Ÿ“Œ Key Takeaways

  • EPUB 3 represents a complete, self-contained offline web application packaged inside an OCF-compliant ZIP archive.
  • Content documents must adhere to strict XHTML5, lowercase casing, escaped entities, and self-closing tags.
  • Semantics should be doubly enriched using epub:type and DPUB-ARIA role="doc-*" attributes.
  • The package.opf file acts as the master manifest, declaring all assets and defining the spine reading flow.
  • The nav.xhtml document provides the Table of Contents, reader Landmarks, and physical Print Page Lists.
  • Build pipelines should enforce automated validation with epubcheck and Ace by DAISY.
  • --
โญ LEARN: HTML ๐ŸŒŸ โš”๏ธ QUIZ BATTLE ARENA // ACTIVE
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 1 / 3

What is the correct sequence of tools to validate an EPUB 3 publication for both technical specification compliance and accessibility before publishing?

Question 1 / 3 Topic: HTML Fundamentals
00:45 REMAINING
XP REWARD
+250 XP
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 2 / 3

Why is linear="no" assigned to the cover page in <spine>?

Question 2 / 3 Topic: HTML Fundamentals
00:45 REMAINING
XP REWARD
+250 XP
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 3 / 3

Which file format is used for the Navigation Document in modern EPUB 3?

Question 3 / 3 Topic: HTML Fundamentals
00:45 REMAINING
XP REWARD
+250 XP