Reading systems use media types to determine what type of content a file contains before trying to render it. The following table lists some of the most common file formats and their corresponding media type values:
File Format | Media Type |
---|---|
XHTML | application/xhtml+xml |
SVG | image/svg+xml |
CSS | text/css |
JavaScript | application/javascript |
JPEG | image/jpeg |
The EPUB specification defines a set of what it calls core media types — file formats that authors can include in EPUB content documents without the need for fallbacks.
Reading systems are required to support these formats so long as they support the necessary rendering (e.g., a reading system that only reads back the text does not have to support CSS or image formats, but a reading system with a visual display does).
Using only core media types in EPUB publications helps ensure that they will be readable regardless of the reading system in use.
Each version of EPUB provides a complete list of supported media types it supports:
Fallbacks
Although the EPUB format tries to accommodate as many widely supported file formats as reasonable for publishing, there are occasions when a format is needed that is not in the core set. A reading system might, for example, be the first to support a new advanced image format.
To help publishers take advantage of formats that reading systems do not widely support, without compromising the readability of their publications, EPUB leverages both its own fallback methods and those natively available in HTML. So long as authors provide a fallback to a core media type, they can add any file format to an EPUB publication.
The following subsections review the fallback mechanisms that EPUB provides.
HTML Fallbacks
Most HTML elements that allow authors to embed content in a page provide a means of including fallback content when the primary source is not available or reading systems cannot render it.
The audio
and video
elements, for example, both allow authors to use
multiple source
elements to provide media in more than one format.
Unlike the audio
and video
elements, the nested content of an
object
element represents its fallback. Reading systems render this content if
they do not support the media type of the file.
Embedding fallbacks for images used to be problematic, but the addition of the srcset
attribute and picture
element have greatly improved the situation (the lack of
fallbacks was a major reason for the creation of manifest
fallbacks in EPUB).
Exempt Elements
EPUB 3 also exempts the following elements from fallback requirement:
link
when it has therel
attribute valuepronunciation
(to allow pronunciation lexicon files);track
(so any captioning, subtitling, and similar audio/video track formats can be included);video
(EPUB does not define a single video format that all reading systems must support).
In these cases, authors can specify any format but there are no guarantees that reading systems will support rendering of the format.
EPUB-specific Fallbacks
Manifest Fallbacks
Manifest fallbacks are named for how they are implemented in the EPUB package document.
The manifest
element lists all the resources used in the publication,
and each item
element within it can specify another item
as a
fallback using the fallback
attribute.
There are two places that manifest fallbacks are used. The first is to include unknown media types in the spine (i.e., to make them documents in the publication reading order). This practice has largely fallen into disuse, however, as it was used primarily in EPUB 2 to allow SVG images in the spine with XHTML fallbacks.
In this case, if the reading system does not support SVG, it follows the
fallback
attribute references until it finds a media type it can support. In
the above case there is only one fallback, but it is possible to keep falling back through
multiple items before reaching a supported media type. The only requirement on fallback
chains is that they must include a core media type.
The other place where manifest fallbacks are used is to provide a fallback image for the
HTML img
element. Until the recent addition of the srcset
attribute
and creation of the new picture
element, it was not possible in HTML to provide
a fallback for images embedded using the img
element. As a workaround, reading
systems are expected to change the source of the img
element to the fallback
specified in the manifest.
It is best to avoid manifest fallbacks for images except in EPUB 2 where there is no other option. They are not well supported.
Deprecated Fallback Methods
EPUB has two additional fallback methods that are no longer recommended for use:
- Content Switching
-
EPUB's content switching mechanism allowed authors to embed markup languages such as MathML within XHTML content documents. The mechanism was modeled on the switch cases in programming languages, with a
case
element containing the foreign markup. If a reading system did not support any of these markup languages, adefault
element contained the HTML to use as a fallback.Content switching was developed for EPUB 2, which did not allow MathML or SVG within its XHTML content documents. It was briefly allowed in EPUB 3 before finally being deprecated due to a lack of support.
- Bindings
-
Bindings were created for EPUB 3 to provide scripted fallbacks for foreign media types. If a reading system did not support a media type in an
object
tag, authors could "bind" the resource in the package document to a fallback scripted document that any arguments specified in theobject
would be passed into.The bindings method has been deprecated in the latest version of EPUB 3 due to a lack of a practical need for the feature, and total lack of support in reading systems, so should be avoided.
Resource Location
EPUB allows the following types of content to be hosted on the web instead of stored inside the ZIP container:
- Audio files
- Video files
- Font files
- Resources retrieved by scripts (not the actual script code)
Caution needs to be exercised in such cases, however. There is no guarantee that users will have access to download remotely hosted content, and no guarantee that the reading systems will retrieve remotely-hosted resources even if network access is available.
Related Links
- HTML —
audio
element - HTML —
img
element - HTML —
object
element - HTML —
picture
element - HTML —
video
element - EPUB 3 — Supported Media Types
- EPUB 2 — MIME Media Types