Media types are used by reading systems as a way of understanding in advance what type of content a file contains. 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 |
EPUB defines a set of what are called core media types — file formats that can be included in publications without the need for fallbacks.
Reading systems are effectively 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.
The complete lists of supported media types are provided in each version of the EPUB specification:
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 support a new advanced image format, for example, before others.
To help publishers take advantage of formats that are not widely supported without compromising the readability of a publication, EPUB leverages both its own fallback methods and those natively available in HTML. So long as a fallback is provided to a core media type, any file format can be added to an EPUB publication.
The following subsections review the fallback mechanisms that are available.
HTML Fallbacks
Most HTML elements that allow content to be embedded in a page provide a means of including fallback content when the primary source is not available or cannot be rendered.
The audio
and video
elements, for example, both allow the use of
multiple source
elements to provide media in more than one format.
Video element with WebM and MP4 video options
Note that the embedded message is only displayed in older user agents that are not HTML5-aware (e.g., EPUB 2 reading systems).
<video controls="controls">
<source src="rain.webm" type="video/webm"/>
<source src="rain.mp4" type="video/mp4"/>
<p>This reading system does not support video.</p>
</video>
Unlike the audio
and video
elements, the nested content of an
object
element represents a fallback.
Embedded PDF form with an HTML fallback
<object src="t1000.pdf">
<h3>Tax Form T-1000</h3>
…
</object>
Embedding fallback 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).
Picture element with WebP and JPEG image options
<picture>
<source srcset="rainbow.webp" type="image/webp"/>
<img src="rainbow.jpg" type="image/jpeg"/>
</picture>
Image element with multiple sources
In this example, three alternative sizes of an image are provided in the
srcset
attribute.
<img src="rainbow.png"
srcset="rainbow-1x.png 1x, rainbow-2x.png 2x, rainbow-3x.png 3x"
alt="Rainbow over wheat fields" />
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, any format can be specified, 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 is used to list all the resources used in the publication,
and each item in 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.
SVG in spine (EPUB 2)
<manifest>
<item id="c01" src="images/plate01.svg" media-type="image/svg" fallack="c01-xhtml"/>
<item id="c01-xhtml" src="images/plate01.xhtml" media-type="application/xhtml+xml"/>
…
</manifest>
<spine>
<itemref idref="c01"/>
…
</spine>
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.
Image fallback in manifest
HTML
<img src="rainbow.webp" alt="Rainbow over wheat fields"/>
Package Document
<manifest>
<item id="img01" src="rainbow.webp" media-type="image/webp" fallack="img01-fb"/>
<item id="img01-fb" src="rainbow.jpg" media-type="image/jpeg"/>
…
</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.
Another fallback method unique to EPUB called bindings, was created to provide fallbacks for scripted content. This method has already been formally deprecated so should similarly 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