Posted on by & filed under epub, html5.

This was an experiment and is a bit of a hack. Most people seeking to embed video in ePub should use the Flash method described earlier.

I wanted to see if could construct a valid ePub file using HTML5 (in this case, employing the HTML5 <video> element). The problem is that ePub only supports one kind of HTML: XHTML 1.1, a flavor of markup which seems to exist only to annoy people trying to create valid ePub files.

There are two methods to include “foreign” media types in ePub. The first is out-of-line items which have separate fallback items, either out-of-line XML in another vocabulary, or a separate type of binary media like a movie falling back to a static image.

The other is Inline XML islands, which uses a unique <ops:switch> element to toggle among two or more different XML vocabularies.

My first instinct, if I were going to include the HTML5 <video> element, was to make an inline XML island and switch between that and the Flash fallback. But <ops:switch> depends on the XML island having a different namespace. HTML5 uses the standard XHTML namespace (, so there’s no way to indicate that we’re using an XHTML vocabulary that isn’t XHTML 1.1.

Got that?

But there’s another option: treat the whole HTML5 page as an out-of-line island. How? By not using the XHTML vocabulary at all, but instead treating it as media-type text/html:

    &lt;!-- HTML5 --&gt;
    &lt;item id=&quot;video&quot; 

    &lt;!-- XHTML 1.1 fallback --&gt;
    &lt;item id=&quot;video-fallback&quot;
          media-type=&quot;application/xhtml+xml&quot; /&gt;

Here I defined a document with an unsupported media-type (text/html) and a fallback in a supported type (application/xhtml+xml). Unfortunately there’s no way for me to actually specify that it’s HTML5, since HTML5 doesn’t even have a real DOCTYPE.

I also include the media files in the OPF:

  &lt;item id=&quot;video-mp4&quot; 
    &lt;item id=&quot;video-ogg&quot; 
    &lt;item id=&quot;video-png&quot; 

And here’s the complete HTML5 island:

&lt;!DOCTYPE html&gt;
    &lt;title&gt;Video test&lt;/title&gt;
      &lt;video width=&quot;320&quot; height=&quot;240&quot; controls=&quot;true&quot; autoplay=&quot;true&quot;&gt;
        &lt;source type=&quot;video/ogg&quot; src=&quot;20143.ogv&quot;  /&gt;
        &lt;source type=&quot;video/mp4&quot; src=&quot;20143.mp4&quot;  /&gt;

Here’s the sample file: HTML5 video in ePub. This will actually work in Bookworm, but nowhere else. It’s also not valid according to epubcheck, but only because epubcheck thinks that the text/html item is an error, and it doesn’t like that the HTML5 island is missing a namespace (because it’s not actually XHTML, but text/html).


37 Responses to “Using HTML5 video in ePub”

  1. Peter Sorotokin

    Good catch! I think ops:switch also can take required module name in addition to the namespace, but it should be given a specific value for (X)HTML5. I have created an issue in IDPF database, so this can be addressed by the WG in errata.

  2. Peter Sorotokin

    BTW, XHTML has to be used instead of HTML so that only a standard XML parser is all what is ever needed in a (potentially resource-contrained) reading system. Also most members of the WG have an opinion that rigid syntax rules are better for interoperability. HTML can always be mechanically converted to XHTML at authoring time, so there is no loss of functionality there. Any HTML5 syntax can also be expressed in XML by design.

  3. Liza Daly

    Thanks Peter. I didn’t know if I wanted to submit it as an issue since it’s kind of an edge case.

    An epub reader has to also have a CSS parser in addition to an XML parser:

    I would have liked to see the CSS requirement dropped (for the reason you state), and allow any XHTML schema, but my wishlist for epub is another post.

  4. kira

    Actually, you can produce valid epub files using HTML 4.0 strict or transitional standards to get valid epubs too.

  5. Seb

    Great job Liza, but how about the size of the final epub.
    How many videos can you really embed in an epub without “breaking the limits” ? Imagine you want to insert some training videos into a graphist learning epub for student or pro, how many of videos can you reasonnably put in ?

    Thanks and congrates again for thoses developpments and communicate on it.

  6. Liza Daly


    You can make epub files as big as you like, according to the spec. The practical limit on OPS file size in the Sony Reader doesn’t apply here since it doesn’t support video anyway.

    The main thing I’d be concerned with is ordinary download size. You can get a sense of the range in sizes for epub books, but I’d say that bigger than 5MB is pushing it, and 10MB will be too much for people to download on small devices.

    In theory you aren’t supposed to embed resources from the web in an epub book (for example, hotlinking an image), but I think it makes sense to do so with video. If you were distributing an ebook that required a lot of video, I’d probably provide a huge version with everything bundled (for offline use) and another one that simply plays video hosted on YouTube or elsewhere.

  7. Seb

    Thanks Liza.

    In fact, we (my publishing society) plot to release ebooks with video like we did illustrated books before. We’d like to offer new kinds of perspectives, like in a Photoshop manual where illustrations are replaced by videos.

    So, i guess, for smartphone devices and netbook, epub is the solution.


  8. Frank Lowney

    I’ve been looking at Apple’s recently released content developer documentation for iTunes LP and iTunes Movie Extras, see:

    Like ePub, TuneKit is based upon open web technologies and, so, they are more similar than different from one another. Apple will also support the ePub format with an iPad application called iBooks.

    All of this caused me to wonder whether some kind of merger might be in the offing. Will TuneKit evolve beyond music and movies to encompass text or will ePub evolve beyond text to encompass interactive rich media? Apple now has a substantial history of involving itself in open standards organizations. Examples include WebKit and the tags Apple added to RSS.

    Speaking of RSS, the further question is whether there will be a non-commercial distribution model, perhaps adding .epub and .itlp to the list of podcastable file types.


  9. Matthew

    Hi Liza, I downloaded the video.epub file to test in Bookworm, but when I try to upload the file, I get an error message “The file you uploaded was not recognized as an ePub archive and could not be added to your library.” Has anyone else been able to get it to work in Bookworm?

    Also, Seb, what is the name of your publishing society? I am very interested in embedding video into ebooks, and would love to hear about what you’ve been able to do.



  10. Matthew


    That worked perfectly! Thanks so much.

    Is there a reason this will only work in Bookworm? Why can’t other epub readers get past what you’ve done to the code?


  11. Liza Daly


    It might work in other ereaders that are based on browser technology that happens to support the <video> element, but I’m not aware of any that do. (It may just happen to work on some that are based on the WebKit browser engine.)

  12. Dave Cramer

    If you set the media type of the HTML5 island to application/xml rather than text/html, the whole ePub will be valid according to ePubCheck 1.0.5. I’ll leave it to others to argue how kosher that might be!

  13. Gerald Schmidt

    Hi Liza,

    As you suggest this works really well in WebKit-based readers, thanks! I’ve been wondering if iPad ePubs support HTML5. The January announcement promised video, which I took to mean some degree of HTML5 support in iPad ePubs (it clearly didn’t mean Flash support). So far the demos I’ve seen show plain text and images only – has anyone seen audio/video working in iBooks? and offline storage would be nice too, of course.


  14. Gerald Schmidt

    That’s good to know. I must have misunderstood the keynote. Thanks!

  15. Arthic Leo

    Hi Liza,

    Does any ebook reading device such as iPad support flash (.swf) ePUB? If so, could you please let me know?

    Sorry for all, even after coming across the whole blog i couldnt find the answer for my question. Hence i supposed to post this here. May my lack of knowledge played here:)

  16. Jose Bermudez

    Hello Koan-Sin Tan’
    What type of editor for epub do you use? I tried to download the attached epub on that site but i could not read the video code… It says “if video tag doesnt work for you, you’ll see this line”
    Did you do Liza’s steps to add the video so that you could read it on ipad ibooks?
    Also, does anyone know how to make an image larger if you tap on it, Im new at this so any tips are helpfull

  17. Liza Daly

    Jose Bermudez: You can make an image larger just by including a larger image in the epub and hyperlinking the small one to that.

  18. voddou


    I ttried to launch your file with ADE and I don’t see the Video…

    Why ?


  19. voddou

    Thanks. So if I want to create an Epub with a video readable with ADE, Kindle, Ipad,…, How can I do ?…

  20. tenaka

    Hello Liza,

    Thank you for your great work !

    I’ve managed to insert a video on a epub and read it properly on my ipad but…

    when I want to add another video, let’s say 2-3 pages further, i come with a blank space.

    I used the same code as the first one, aka :

    if video tag doesn’t work for you, you’ll see this line

    My guess is that ibooks, or the epub format isn’t able to deal more than one video or tha it thinks that it is the same one.

    Maybe we could add some id tag to the code but, I confess, I’m kinda new at this and have no professional knowledge in html.

    Thank you in advance for your answers.

  21. Liza Daly

    Hi Tenaka,

    I haven’t experimented with multiple videos, but make sure that they are both listed in the OPF manifest and have different ids.

  22. Arthic Leo

    Hi Liza,

    Could you please advise is there any reading devices or e-readers that would support audio embedded ePUB files other than ADE. If yes, will it read the audio file? Please advise.

    A.E.Arthic leo

  23. Liza Daly

    It’s likely that iBooks would support the HTML5 audio tag as it does HTML5 video, but that would not be a valid epub book.

  24. Vasu

    Apple’s iBook New In Version 1.1.2 supports Video and Audio
    “• Experience books that include audio and video.”

    Can any one help me with how to embed video into ePub’s I did try using the Video.ePub provided by Liza, but I was only able to see a Black Box in iBooks, I was not able to play the video.

    Any help or inputs appreciated.


  25. Vasu

    I followed Koan-Sin Tan advice and now I using below code, we are able to play video’s in iBooks

    Code for Video:

    Hello World: My First EPUB

    Hello World: My First EPUB
    This is the content of my first EPUB book.
    The following is an HTML5 video. The for iPad is amazing. It can display the HTML5 video without problem.

    if video tag doesn’t work for you, you’ll see this line


  1.  ePub books with video: Tips from Liza Daly, creator of Bookworm | TeleRead: Bring the E-Books Home
  2.  Liza's Experiment in advancing ePub with HTML5 tag | epubBooks Blog - Information & Resources on the ePub Standard
  3.  A Million Thoughts NL » iPad enzo….
  4.  Embedded Video Support in ePubs | Luchita