Introduction
EPUB is the open standard for ebooks. It was developed by the International Digital Publishing Forum, which merged into the W3C in 2017; EPUB 3.3 became a W3C Recommendation in 2023. An EPUB is essentially a small website in a ZIP file: the chapters are XHTML pages styled with CSS, with images, fonts and a table of contents, so the text reflows to fit any screen.
Structure
The ZIP container must start with an
uncompressed file named mimetype whose only content is
application/epub+zip, so the type can be read from fixed bytes at the
start of the file. META-INF/container.xml points to the
package document, an .opf
file that holds the book’s metadata, a manifest of every file and the spine, which
sets the reading order. EPUB 3 books have a
navigation document in XHTML; EPUB 2
books use an NCX file instead. The
content documents are XHTML or SVG,
marked up with epub:type
terms, and may be fixed-layout pages or have synchronised narration. The package’s
version attribute, 3.0 or 2.0, tells EPUB 3
and EPUB 2 apart.
zipmimetypeapplication/epub+zip, stored first and uncompressed20 byteszipMETA-INF/container.xml where the package document isXMLzippackage.opf metadata, manifest and spineXMLzipnav.xhtml the table of contentsXHTMLzipchapters, CSS, images, fonts the contentvaries
Not described
EPUB is fully specified by the W3C. What is left is a matter of work, not of missing documentation.
Known, not yet covered
- Reference: ONIX code list 5 (the product identifier type) is given on the
package page, because it is the only ONIX list EPUB 3.3 refers to by example. The viewer checks a
scheme="onix:codelistN"value against all 166 lists of the EDItEUR ONIX for Books code lists, Issue 75 (4,820 codes, 170 of them deprecated), and alinkwithproperties="onix"against the link vocabulary (EPUB 3.3 D.4.2). Alink rel="record"that points into the container is opened: the viewer reports a missing file, a record that is also listed in the manifest (a standalone record is not a publication resource), a missingmedia-type(required for every linked resource inside the container), and, for an XML record, that it is well-formed and what its root element is. An ONIX for Books 3.0 record (reference names or short tags) is also described: the header (sender, addressee, sent time), then for each product its record reference, notification type, identifiers, product form and composition, titles, contributors with their roles, languages, extents, imprint, publishers, publishing status and dates; every coded element of the message (160 elements take one code of an EDItEUR list) is checked against the code lists of Issue 75, and an unknown code is a problem while a deprecated one is a warning. What an ONIX record must contain is EDItEUR’s ONIX for Books 3.0 specification (Release 3.0 revision 8), not EPUB’s. The structure of the record (which elements a composite holds, their order, which are required and how often each may repeat) is checked against EDItEUR’s own XML Schema for the tag form the record uses; the two schema files (reference names and short tags) are on the site exactly as EDItEUR publishes them, and the check reads them when a book links a record. The EDItEUR licence (doi 10.4400/nwgj) permits this: it lets implementers “copy and use as required any controlled vocabularies, schemas or other technical tools as published” (3.2.2), provided the notices stay intact and EDItEUR is named, and it forbids abridged or modified versions of the standards (4.2), which is why no table of the structure is made from the schemas. The check covers element content: order, required children, repeats, text where only elements are allowed and children inside a text element (xmllint with the same schema agrees on every damaged record in the tests). It does not apply the schema’s uniqueness rules, the patterns of its data types, or the markup inside the XHTML-typed elements (descriptions and the like), and the code lists are checked by their own table (copied unmodified, naming EDItEUR as the source). A record that lies outside the container is not retrieved: the viewer reads the one file it was given. The MARC relator codes are on the package page and checked, the companion specifications on the companions page and the security and privacy considerations on their own page. - Reference and viewer: EPUB 2. The OPS 2.0.1 statements on DTBook (media type, namespace, no islands, validity against
dtbook-2005-2.dtd) and on the deprecated OEBPS 1.2 media types are on the package page, and the viewer applies the ones a single file decides (well-formed,
the namespace, no inline SVG or islands, the deprecated type named). An EPUB 2 XHTML document is now validated against the XHTML 1.1 DTD (content models, attributes and their types, required and fixed attributes, ID and IDREF;
checked against
xmllint --validon 211 real documents, with the namespace-declaration attributes and elements of other namespaces skipped). A DTBook document is validated against dtbook-2005-2.dtd and an OEBPS 1.2 document against oebdoc12.dtd the same way (xmllint is the oracle in the tests). Not done: OEBPS 1.2 books themselves (a package withoutMETA-INF/container.xml), which are not EPUB. - Viewer: HTML and CSS. EPUB 3.3 requires an XHTML content document to conform to the HTML Standard in full; the explorer checks the content model of every element and the attributes each element may carry
(checked against the 365 valid documents of the EPUBCheck corpus), and does not check the grammar of attribute values, ARIA in HTML, microdata, palpable content or the content of
templateandscript, all listed on the content page. An EPUB 3 style sheet is checked for its CSS syntax, the two forbidden properties, and the twelve-epub-prefixed properties of EPUB 3.3 against their value tables (the one place where EPUB itself defines CSS values); the values of all other properties belong to the W3C CSS specifications, to which EPUB 3.3 6.4 defers, and are not checked. A content document that is encrypted is not checked. - Reference and viewer: OPS 2.0.1 content rules for an EPUB 2 book. An EPUB 2 XHTML document is now checked for XML syntax, the XHTML namespace on the root, the elements of
the XHTML 1.1 modules OPS 2.0.1 requires (2.2.1), the required type of style (text/css or text/x-oeb1-css) and script, the required src and alt of img, align="char", noscript
after its script, param before the content of an object, and a classid object with no fallback (2.3.4 to 2.3.9), and the two Project Gutenberg conversions (a
tagattribute that XHTML 1.1 does not declare) and the Kafka book (targetona) are reported for exactly that. The CSS 2 subset of an OPS style sheet is checked too: the CSS 2.1 Appendix G grammar with the 4.2 error recovery, the property and value table of section 3.3 (an unlisted property or value is a recommendation, because OPS says it is not supported), units on non-zero lengths (3.2.3), the URIs of 3.2.1, and the embedded-font rules of 3.4 (the six allowed@font-facedescriptors, thesrcgrammar, a font file that is in the manifest). No offline CSS validator is installed, so the specification text is the oracle and the 27 test cases are named after its sentences. - Reference and viewer: OCF 2.0.1. The specification (saved in research/epub, converted from the Word file) was compared with the container page and the viewer: file names, mimetype, ZIP rules, the files that must not be encrypted, container.xml, and now the reserved files of 3.5 (manifest.xml against the ODF 1.0 manifest schema, saved as research/epub/odf-manifest-v1.0.rng; metadata.xml and rights.xml namespace rules; stray children of encryption.xml and signatures.xml, Appendix A). Where OCF 2.0.1 and EPUB 3.3 differ (manifest.xml), the problem or recommendation follows the book’s version.
- Viewer: media overlays. A clip with no
clipEndplays to the end of its audio file, whose length is read by the site’s MP3, MP4 and Ogg plugins (tested on a 2.5 s tone in MP3, AAC in MP4 and Opus; an MP3’s length is the plugin’s own figure, 2.534 s for the 2.5 s tone). AAC in ADTS and other audio types are tried through the AAC plugin and not tested; a file no plugin reads leaves the clip’s length unknown. AclipEndpast the end of the file is not compared. - Viewer: encrypted files open with a password-derived key or a symmetric key (AES CBC and GCM, Triple DES, AES key wrap). A key encrypted for a public key (RSA, ECDH) needs the recipient’s private key, which cannot be given; that is the key missing, not support.
- Viewer: signatures. Verified: RSA (PKCS#1 v1.5, and RSASSA-PSS as RFC 6931 2.3.9 and 2.3.10 name it, signed by OpenSSL; PSS with an MD5, SHA-224 or SHA-3 hash, an MGF1 hash that differs from the digest, or a trailer other than 1 is reported as not checked), ECDSA (raw r and s; DER is reported), DSA with a certificate or a DSAKeyValue, and HMAC with a secret given as the
Key option; canonicalisation includes DOCTYPE entities and the Canonical XML 1.1
xml:basefix-up (checked against the recommendation’s own examples, not against another implementation). Also verified: the XPath filtering transform (XPath 1.0 withhere(), a variable reference is an error as XML Signature 1.1 6.6.3 says), XPath Filter 2.0 (intersect, subtract, union), the#xpointer(...)form of a same-document URI, and Canonical XML of a document subset (checked against Apache Santuario’s vectors 37 and 38, which are an XPath subset in Canonical XML 1.0 and 1.1, and againstxmllintfor whole-document results); the Decryption Transform for XML Signature is done in both modes (XML mode as Canonicalize-with-Replacement, withxmlns=""on the apex elements, thexml:attributes of a parent outside the node-set,ExceptURIs, super-encryption, Type Element or Content, and failure for any other Type; binary mode as the concatenated octets in document order), with the Key option as the data key for aCipherValuein AES-CBC, AES-GCM or Triple DES, or as the AES key-wrap key (RFC 3394) of anEncryptedKeythat holds the data key, and with anEncryptedDatathat holds its data by aCipherReferenceto a file of the container, including thexenc:Transformsof XML Encryption 1.1 3.3.1 (base64, XPath, canonicalization) (tested withnode:cryptoencryption andxmllint --c14ndigests; read from the W3C text, nothing from memory). The XSLT transform (XML Signature 1.1 6.6.5) runs on an XSLT 1.0 processor written from the W3C Recommendation of 16 November 1999 (template rules, modes, named templates, variables and result tree fragments,xsl:key,xsl:number,xsl:sort,format-number, attribute sets,namespace-alias,xsl:importandxsl:includeof files in the container, simplified stylesheets, and the xml, html and text output methods serialised to octets); its output is compared withxsltproc(libxslt) on 49 stylesheets, byte for byte. Divergence from the spec, following whatxsltprocdoes: the html output indents like libxml2, anddocument()is not supported (a stylesheet that calls it fails the transform). A signature whose XSLT output is text, or whose Transform has no stylesheet, is “cannot be checked”. Not done: a Decryption Transform with no Key option given, anEncryptedKeyfor a public key (it needs a private key the viewer is never given), aCipherReferenceto a file outside the container, a key that is only named (a KeyName is a label and is shown as one; XML Signature 1.1 4.5.1), a RetrievalMethod is followed only to a file of the container without Transforms, as a DER certificate or an XML file with X509Certificate, XML Signature 1.1 4.5.3, and not to a remote URL or a fragment). The certificates of anX509Dataare checked against one another (RFC 5280): each signature by the next certificate in the chain (RSA PKCS#1 v1.5, RSASSA-PSS, ECDSA; DSA and SHA-224 are said to be unchecked), validity dates, that an issuer is a CA withkeyCertSignand keeps itspathLenConstraint, authority and subject key identifiers, critical extensions, and thatX509SubjectName,X509SKI,X509IssuerSerialanddsig11:X509Digestdescribe the signer’s certificate. Trust and revocation are not part of EPUB or of XML Signature: XML Signature 1.1 (the KeyInfo element description) says that questions of trust of key information, such as its authenticity or strength, are out of scope and left to the application, and that certificate revocation and CRL management are out of scope; the EPUB 3.3 core text defines no trust rule or revocation check for signatures.xml. The viewer therefore reports what the file proves (the signature and the chain agree with one another) and does not judge the top of the chain trusted; it has no trust store and does not fetch a CRL or ask an OCSP responder (a reading system MAY apply its own policy; none is required). The chain is also checked for the RFC 5280 name constraints (directoryName,dNSName,rfc822Namewith the subjectemailAddress, URI host and IP ranges, with the self-issued exception; permitted subtrees intersect and excluded ones join, 4.2.1.10 and 6.1.3 (b), (c)) and for certificate policies (the valid policy tree of 6.1 withpolicyMappings,requireExplicitPolicy,inhibitPolicyMappingandinhibitAnyPolicy, the user-initial-policy-set being any policy); a self-issued top certificate is taken as the trust anchor, its name constraints are applied and its policy extensions are not (RFC 5280 6.2 leaves that to the application). Name constraints forotherName,x400Address,ediPartyNameandregisteredIDhave no defined meaning (4.2.1.10) and are reported, not evaluated; extended key usage is not evaluated. These checks agree with OpenSSL’sverify -policy_checkon 51 chains made by OpenSSL (test-epub-certpolicy.mjs). The ECDSA, RSA and DSA checks were made with signatures from OpenSSL; no signed EPUB made by another program was available. - Viewer: real books. Ten were opened: the IDPF samples (EPUB 3, one with media overlays), two home-made, two EPUB 2 books made by calibre, and an older EPUB 2 book, with the problems listed that were judged to be true faults of the file. Gutenberg and Standard Ebooks refused the download, so no more EPUB 2 books from them. The viewer has a Read tab that shows the book typeset as a reader would: the spine documents in reading order, the navigation document and the NCX as contents, the book’s own style sheets and fonts, and decrypted or de-obfuscated resources. Its toolbar has: Contents, a panel listing the navigation document’s entries (nested as in the book), where choosing an entry jumps to that document and anchor; Previous and Next, which move through the spine; Pages or Scrolling, to read as separate pages or as one scrolling column (the page number shows as “page 1 of 1” and the position as a percentage); A− and A+, which make the text smaller or larger and back; and Book colours, Light, Sepia or Dark for the reading colours (with Dark the page is dark with light text). A Go to… menu lists the landmarks and page-list entries of the book when it has them. The contents panel and its jumps, Next, the switch between Pages and Scrolling, A− and A+, and the Dark colours were tried in Chrome on a book built for the tests (a table of contents of three entries), with no error in the console.
Divergence from spec
Where the explorer follows the specifications and other programs do something else, or where two specifications disagree. Each statement names the file that was read; the sources are listed in the samples notes with their SHA-256 sums.
- OCF 2.0.1 and EPUB 3.3 on
META-INF/manifest.xml. OCF 2.0.1 3.5.2 (OCF_2.0.1.txt lines 242 to 244) says the file, if present, must follow the ODF 1.0 manifest schema and must not be encrypted. EPUB 3.3 4.2.6.3.3 (epub33-full.html lines 3341 to 3346) says only that it is optional, that OCF “does not mandate a format” and that reading systems do not use it. The explorer follows the version of the book: in an EPUB 2 book a manifest.xml that breaks the ODF schema is a problem, in an EPUB 3 book a recommendation. - EPUBCheck. Its message list (epubcheck-MessageBundle.properties) reports a file name with a space (PKG_010, line 248) and a file name with a non-ASCII character
(PKG_012, line 250) as interoperability notes. The explorer reports the space as a recommendation (ocf.js line 127) and does not report non-ASCII names, because EPUB 3.3 4.2.3 forbids
only the listed characters. The text of EPUBCheck’s CSS_001 (line 26) is “The "%1$s" property must not be included in an EPUB Style Sheet”; the explorer’s matching rule is for
directionandunicode-bidi(EPUB 3.3 6.4), and it applies it to EPUB 3 books only, because OPS 2.0.1 3.3 lists both properties as supported. (Which properties EPUBCheck’s own code sends to CSS_001 was not read.) - calibre. Its checker (calibre-polish-check-opf.py) warns about every spine item marked
linear="no"and offers to remove the attribute (lines 171 to 186 and 328 to 330), and reports ameta name="cover"whosecontentcomes beforename(lines 63 to 72) because the Nook fails to read it. OPF 2.0.1 defineslinear="no"as auxiliary content (OPF_2.0.1.txt line 491) and nothing in the specifications orders themetaattributes, so the explorer reports neither; it reports an invalidlinearvalue and a spine with no linear item (opf.js lines 549 and 571). - Readium. The Swift toolkit’s EPUB parser (readium-EPUBParser.swift, lines 17 to 24 and 38 to 84) builds a publication and fails only for a wrong mimetype, a missing file, unreadable XML or a missing rootfile; it does not validate. That a book opens in a Readium-based reader says nothing about whether it conforms, which is why the explorer’s list of problems is longer than what such a reader refuses.
- Apple Books. Its Asset Guide (apple-books-asset-guide.html) says that books with JavaScript must not rely on resources outside the book, that nonlinear content is not supported for fixed-layout books, and that images in fixed-layout books must not exceed 5.6 million pixels. EPUB 3.3 allows remote audio, video and fonts and does not limit image size, so the explorer does not apply these limits; they are a store’s rules, not the format’s.
Links
Software
- Apple Books – Apple’s ebook reader and store (macOS, iOS)
- calibre – free ebook library manager, reader and converter (Windows, macOS, Linux)
- Thorium Reader – free EPUB reader with strong accessibility support (Windows, macOS, Linux)
- Sigil – free EPUB editor (Windows, macOS, Linux)
Developers
Reference
- EPUB 3.3 – the W3C Recommendation that defines EPUB
- EPUB Reading Systems 3.3 – what reading systems must do with an EPUB
- EPUB 3 Structural Semantics Vocabulary 1.1 – the terms used with
epub:type - Open Packaging Format 2.0.1 – the package format of EPUB 2