The pages of an EPUB are content documents, listed in the package’s spine: XHTML or SVG files, styled with CSS and using images, fonts, audio and video from the container. This page follows EPUB 3.3.
Content documents
| Kind | Media type | Rules |
|---|---|---|
| XHTML | application/xhtml+xml | HTML in its XML syntax: well-formed, UTF-8 or UTF-16 (UTF-8 recommended), html in the namespace http://www.w3.org/1999/xhtml. Any HTML element may be used; base and rp are discouraged. MathML and SVG may be embedded inline. Attributes from other namespaces are allowed, including epub:type and the ssml:ph and ssml:alphabet pronunciation hints. |
| SVG | image/svg+xml | An SVG 1.1 or later document used as a page, mostly in fixed-layout books. foreignObject may hold only XHTML body content; title holds plain text or HTML phrasing content. |
Scripts may run in two contexts: inside a page (spine-level scripting) or in an
iframe (container-constrained), which may not change the parent page.
Reading systems need not support scripting, so books must work without it, and the
manifest item must carry properties="scripted".
Style sheets may use CSS as browsers support it, except that the
direction and unicode-bidi properties must not be used;
text direction comes from markup and the spine. Older -epub- prefixed
properties such as -epub-writing-mode and -epub-hyphens,
from EPUB 3.0, are still widely supported.
The elements epub:switch (alternative content, such as MathML with a
fallback) and epub:trigger (declarative control of audio and video) are
deprecated.
Further content rules
From EPUB 3.3, sections 3.7–3.9, 6.1.3, 6.3.1.3 and appendices A, B and E:
- RDFa, microdata and JSON-LD. XHTML content documents may use the RDFa attributes (as the HTML+RDFa specification defines them), and may carry microdata attributes and JSON-LD, which HTML supports natively.
epub:prefix. In content documents the prefix mappings forepub:typevalues go in anepub:prefixattribute (same grammar as the packageprefixattribute), for exampleepub:prefix="z3998: https://www.daisy.org/z3998/2012/vocab/structure/#". An SVG embedded by inclusion cannot have it on its root.- Custom attributes. Prefixed attributes whose namespace URL has
neither
w3.orgnoridpf.orgin its domain are allowed, as long as the content loses nothing when a reading system ignores them. - Data URLs (
data:) must not be used where they would become a top-level document: inhrefof manifestitemor metadatalink, inaorareahref(except inside aniframe), or inwindow.openanddocument.open. A data URL's resource is not listed in the manifest but must still be a core media type or have a fallback. File URLs (file:) must not be used at all. - XML resources must be well-formed XML 1.0 documents with namespaces, may declare a document type only with an allowed external identifier (below) or none, and must not contain external entity declarations in the internal subset or use XInclude.
| Media type | Public identifier | System identifier |
|---|---|---|
application/mathml+xml, application/mathml-presentation+xml, application/mathml-content+xml | -//W3C//DTD MathML 3.0//EN | http://www.w3.org/Math/DTD/mathml3/mathml3.dtd |
application/x-dtbncx+xml | -//NISO//DTD ncx 2005-1//EN | http://www.daisy.org/z3986/2005/ncx-2005-1.dtd |
image/svg+xml | -//W3C//DTD SVG 1.1//EN | http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd |
Prefixed CSS (Annex E)
EPUB 3.3 keeps these -epub- properties for old content; they behave as
their unprefixed CSS equivalents, and authors should use the unprefixed ones.
| Property | Values | Unprefixed equivalent |
|---|---|---|
-epub-writing-mode | horizontal-tb | vertical-rl | vertical-lr | writing-mode |
-epub-text-orientation | mixed | upright | sideways | sideways-right; deprecated vertical-right = mixed, rotate-right and rotate-normal = sideways | text-orientation |
-epub-text-combine-horizontal | none | all | text-combine-upright |
-epub-text-combine (deprecated) | none | horizontal | horizontal <number> (horizontal = all; with a number: no equivalent) | text-combine-upright |
-epub-hyphens | none | manual | auto; deprecated all (no equivalent) | hyphens |
-epub-line-break | auto | loose | normal | strict | line-break |
-epub-text-align-last | auto | start | end | left | right | center | justify | text-align-last |
-epub-word-break | normal | keep-all | break-all | word-break |
text-transform: -epub-fullwidth | a prefixed value | text-transform: full-width |
-epub-text-emphasis-color | <color> | text-emphasis-color |
-epub-text-emphasis-position | [ over | under ] && [ right | left ] | text-emphasis-position |
-epub-text-emphasis-style | none | [ [ filled | open ] || [ dot | circle | double-circle | triangle | sesame ] ] | <string> | text-emphasis-style |
-epub-text-underline-position | auto | [ under || [ left | right ] ] | alphabetic; alphabetic = auto | text-underline-position |
Under-implemented and deprecated features
Appendix A marks features as under-implemented (still allowed; checkers
should note them but not warn; the dir attribute is one) or
deprecated (authors should not use them: epub:switch,
epub:trigger, bindings, meta-auth and the
deprecated link relations).
Sources: W3C EPUB 3.3 (w3.org/TR/epub-33/), sections 3.7–3.9, 6.1.3, 6.3.1.3, appendices A, B and E, read in full for this section.
Core media types
Reading systems must support these. A resource of any other type can be included,
but needs a fallback to one of them (a fallback chain in the manifest, or
an HTML fallback such as picture or a video poster).
| Kind | Media types |
|---|---|
| Images | image/gif, image/jpeg, image/png, image/svg+xml, image/webp |
| Audio | audio/mpeg (MP3), audio/mp4 (AAC or MP4 audio), audio/ogg; codecs=opus (Opus in Ogg) |
| Style | text/css |
| Fonts | font/ttf or application/font-sfnt (TrueType); font/otf, application/font-sfnt or application/vnd.ms-opentype (OpenType); font/woff or application/font-woff (WOFF); font/woff2 (WOFF2) |
| Other | application/xhtml+xml (XHTML), application/javascript, application/ecmascript or text/javascript (scripts), application/x-dtbncx+xml (NCX), application/smil+xml (media overlays), application/pls+xml (pronunciation lexicons) |
Video has no core type; books commonly use MP4 with H.264 or WebM, with a fallback. Earlier versions had fewer core types: WebP and Opus were added in EPUB 3.3; EPUB 2’s core types were GIF, JPEG, PNG and SVG images, XHTML, DTBook, CSS and the old OEB 1 document types, with no fonts or audio among them.
Fixed layout
A fixed-layout book shows each content document as a fixed page, like a picture
book or comic, instead of reflowing the text. It is set by meta elements
in the package metadata, which apply to the whole book, and can be changed per page by
itemref properties.
| Property | Values | Meaning |
|---|---|---|
rendition:layout | reflowable (default), pre-paginated | Whether pages are fixed. |
rendition:orientation | auto (default), landscape, portrait | The device orientation the book is meant for. |
rendition:spread | auto (default), none, landscape, both; portrait deprecated | When to show two pages side by side. |
rendition:viewport | e.g. width=1200, height=1600 | Deprecated: the page size for all pages. |
Each fixed-layout XHTML page states its size in a meta element in its
head, in CSS pixels: <meta name="viewport" content="width=1200, height=1600"/>.
An SVG page uses its viewBox.
Reflowable layout
| Property | Values | Meaning |
|---|---|---|
rendition:flow | auto (default), paginated, scrolled-continuous, scrolled-doc | Whether text is shown as pages, as one scroll through the whole book, or as one scroll per document. |
rendition:align-x-center | itemref property | Centre the document horizontally. |
Media overlays
A media overlay synchronises a recorded narration with the text, so that a reading
system can play the audio and highlight each sentence as it is read. It is a SMIL 3.0
document, media type application/smil+xml, linked from the content
document’s manifest item by media-overlay. Elements are in the namespace
http://www.w3.org/ns/SMIL; epub: attributes in
http://www.idpf.org/2007/ops.
| Element | Attributes | Content |
|---|---|---|
smil | version="3.0" (required), id | Optional head, then body. |
head | Optional metadata, of any content. | |
body | id, epub:textref, epub:type | seq and par elements, at least one. |
seq | epub:textref (required), id, epub:type | A sequence matching a structure in the text, such as a chapter, table or footnote; holds seq and par. |
par | id, epub:type | One text and at most one audio, played together. |
text | src (required), id | Empty. The text: a content document and fragment, such as chapter1.xhtml#s12. |
audio | src (required), clipBegin, clipEnd, id | Empty. An audio file of a core type, and the part of it to play. |
clipBegin and clipEnd are SMIL clock values: a full clock
(1:02:05.250), a partial clock (02:05.25) or a time count with
a unit (125.25s, 2.5min, 1h, 250ms;
a number alone is seconds). clipBegin defaults to 0 and
clipEnd to the end of the file. A par with no
audio may be spoken with text-to-speech.
The package metadata states the playing time: media:duration for the
whole book and, with refines, for each overlay; optionally
media:narrator, and media:active-class and
media:playback-active-class, the CSS class names the reading system adds to
the element being read and to the document while playing.
Structures given these epub:type values may be skipped (not read) when
the user chooses: footnote, endnote, pagebreak.
These may be escaped (left part-way): table, list,
figure, aside.
<smil xmlns="http://www.w3.org/ns/SMIL" xmlns:epub="http://www.idpf.org/2007/ops" version="3.0">
<body>
<seq epub:textref="chapter1.xhtml" epub:type="chapter">
<par>
<text src="chapter1.xhtml#s1"/>
<audio src="audio/ch1.mp3" clipBegin="0s" clipEnd="4.2s"/>
</par>
</seq>
</body>
</smil>
The explorer reads every media overlay document and lists each par on the Media overlays tab: the sequence it is in, the text it
highlights, the audio file and clip, and the length of the clip; the row opens the audio as a child file. It checks the structure above
(version, head and body, a textref on every seq, one text then at most one
audio in a par), that every clock value is one, that clipEnd is after clipBegin, that the text file
is a content document in the manifest whose item names this overlay in media-overlay (and that no content document is named by two overlays),
that a fragment names an id in the document, that the audio is a core audio type in the manifest and the container, and that
the clips add up to the media:duration that refines the overlay, and those to the total, to within one second.
What the explorer checks in content documents
Every XHTML and SVG content document and every style sheet of an EPUB 3 package is read when the book opens (an EPUB 2 one is checked for XML syntax and the OPS 2.0.1 rules: the XHTML namespace on the root,
only the elements of the XHTML 1.1 modules of 2.2.1, a type on style (text/css or the deprecated text/x-oeb1-css) and on script, src and
alt on img, no align="char", noscript straight after its script, param before the content of an
object, and fallback content for an object with a classid (OPS 2.0.1 2.3.4 to 2.3.9), then validated against the XHTML 1.1 DTD, so a misplaced element, text where only elements go, an undeclared or
badly valued attribute, a missing required attribute or a duplicate id is reported as “XHTML 1.1 DTD: …”; the EPUB 3 rules do not apply to it, and its CSS is not checked;
an EPUB 2 DTBook document also for its namespace and for inline islands, and the deprecated OEBPS 1.2 media types are reported, as the
package page says; no DTBook or OEBPS 1.2 DTD is run). The Manifest tab lists each with what it uses and how many problems it has. The rules come from section 6 of EPUB 3.3,
the fixed-layout rules of section 8 and the manifest properties of 5.
- XHTML. XML syntax; encoding UTF-8 or UTF-16; a legal document type (
<!DOCTYPE html>or none); the roothtmlin the XHTML namespace with onehead(with atitle) and onebody;langandxml:langalike; unique ids; elements that are not HTML elements or are obsolete;aina, block content inp,lioutside a list. (The check that an attribute is not named by the HTML Standard for its element was removed: it called valid attributes, such as the WAI-ARIArole, unknown.) - The EPUB attributes.
epub:typenot onheador metadata content, each value a term of the Structural Semantics Vocabulary or prefixed with a declared prefix;epub:prefixonly on the root; no other attribute in the EPUB namespace; custom attributes only in namespaces outside w3.org and idpf.org;epub:switchandepub:triggerreported as deprecated;base,rpandembedas discouraged. - MathML and SVG. Content MathML only inside
annotation-xmlwith the rightencodingandname;foreignObjectholding flow content or onebody(none in an included SVG);epub:typeonly on renderable SVG elements; markup in an SVGtitleonly from HTML; noepub:prefixon an includedsvg. - Resources. Every local resource a document refers to is in the container and in the manifest; links to a file or an id that does not exist; remote resources only for audio, video and fonts, with
httpsadvised. The manifest propertiesscripted,mathml,svg,switchandremote-resourcesmust be set when the document needs them, and are reported when set without need. - CSS. No
directionorunicode-bidiproperty in a style sheet, astyleelement or astyleattribute; UTF-8 or UTF-16 encoding and a matching@charset. EPUB 3.3 says a style sheet “MAY include any CSS properties” apart from those two, and defines only one thing itself: the prefixed properties of its appendix “Prefixed CSS properties”. Each declaration of one of the twelve-epub-properties (-epub-writing-mode,-epub-text-orientation,-epub-text-combine-horizontal,-epub-text-combine,-epub-hyphens,-epub-line-break,-epub-text-align-last,-epub-word-break,-epub-text-emphasis-color,-epub-text-emphasis-position,-epub-text-emphasis-style,-epub-text-underline-position) is checked against the value table the appendix gives; a value outside it, a deprecated keyword (rotate-right,hyphens: all,alphabetic,text-transform: -epub-fullwidth), a deprecated property (-epub-text-combine) and any other-epub-property (the less-used ones were removed) are recommendations. A colour for-epub-text-emphasis-coloris accepted if it is any identifier, a hex colour, or a colour function, because the colour keyword list is in a W3C CSS specification that was not read. The values of every other property are defined by the W3C CSS specifications (“EPUB defers to the W3C to define CSS”) and are not checked; that would take the data of the whole CSS Snapshot, which is not part of EPUB. - Fixed layout. A fixed-layout XHTML document has a viewport
metawithwidthandheightonce each, positive numbers ordevice-widthanddevice-height; a fixed-layout SVG has aviewBox. A spine override to reflowable removes the rule.
What EPUB 3.3 requires of an XHTML content document, and how far the explorer goes
EPUB 3.3 (6.1, “XHTML requirements”, read in this session) says an XHTML content document MUST be an HTML document that conforms to the XML syntax, MUST “conform to the conformance
criteria for all document constructs defined by [HTML] unless explicitly overridden” by the EPUB deviations, and may use the extensions it lists (epub:type, RDFa, microdata). That is full HTML conformance:
the content model of every element, the grammar of every attribute value, ARIA in HTML, and the rest of the HTML Standard’s “requirements for authors”, which a program such as the Nu Html Checker applies.
The explorer checks the content model of the HTML Standard (read from its source, whatwg/html source, in this session) for every element of an XHTML content document: the content categories (flow, phrasing, interactive, embedded, heading, sectioning,
and so on), the content model of each element, transparent content (a, ins, del, map, object, video, audio, canvas, noscript), the
“no such descendant” rules (no a in a, no interactive content in a or button, no form in form, and the rest), the child order of table, dl, figure, details,
video, select, ruby and the others, the required attributes of each element, and the attributes each element may carry (the global ones, the event handler attributes, the
RDFa attributes of HTML+RDFa 1.1, epub:type and the data-* attributes, then the list of the element). An obsolete but conforming feature (img border="0", script type
with a JavaScript media type, style type="text/css", a name) is a recommendation, as the standard says conformance checkers warn on it. The checker lives in html-model.js and does not look at elements of other namespaces (SVG and MathML are checked elsewhere).
The oracle is the EPUBCheck test corpus (862 XHTML documents from w3c/epubcheck, BSD-3-Clause): every document whose name ends in -valid (365) raises nothing, and about 85 single-rule tests are named after the sentences of the HTML Standard.
The documents whose name ends in -error or -warning are of many kinds; the checker flags 20 of them and is silent on the others because they are about something else (see below).
Not checked. The value grammar of attributes (URLs, dates and times such as time datetime, media queries, srcset, usemap pointing at a map name, ARIA values, class tokens, the language tag); the ARIA in HTML rules (which roles an element may have, required owned elements, aria-*
values); the microdata rules (itemprop on an element that cannot carry it); palpable content (an element that must not be empty); the
content of template and script; the labelable-descendant rule of label in full; the browsing-context rules of iframe srcdoc; text content rules (a title that is not empty,
a time value). CSS beyond the EPUB rules is checked separately (see the EPUB 3 CSS section, when listed). A book the explorer passes can still fail the Nu Html Checker or EPUBCheck.
Divergence from the corpus. The HTML Standard (its “non-conforming features” list, source line 158804) says the border attribute of table is obsolete and not allowed; the EPUBCheck corpus calls table-border-valid.xhtml valid. The explorer follows the HTML Standard, which EPUB 3.3 6.1 names.
A track with no kind is in the subtitles state and must then have srclang (source lines 38280 and 38304); the corpus’s schematron-valid.xhtml does not give one, and the explorer follows the Standard. The its-* attributes of the Internationalization Tag Set are not in the HTML Standard or in the extensions EPUB 3.3 6.1 lists; EPUBCheck accepts them, and the explorer reports them as a recommendation only.