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.

Video element with WebM and MP4 video options

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

Note that the embedded message in the p tag is only displayed in older user agents that do not support the video element (e.g., EPUB 2 reading systems). The message does not appear if only the formats are not supported.

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.

Embedded PDF form with an HTML fallback

<object src="t1000.pdf" type="application/pdf">
   <h3>Tax Form T-1000</h3>
   <p>…</p>
</object>

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

Picture element with WebP and JPEG image options

<picture>
   <source srcset="rainbow.webp" type="image/webp"/>
   <img src="rainbow.jpg" type="image/jpeg"/>
</picture>

In EPUB, the img tag must always reference a core media type so that reading systems can render an image if they do not support the options in the source elements.

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" />

1x, 2x, and 3x in the srcset attribute refer to the pixel density of the image.

Exempt Elements

EPUB 3 also exempts the following elements from fallback requirement:

  • link when it has the rel attribute value pronunciation (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.

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.

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, a default 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 the object 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:

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