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.
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>