Thanks for coming to, the world's #1 resource for all things InDesign!

InDesign Object Styles Convert to DIV classes in EPUB Export

If you’ve been exporting EPUB files, then you’re likely already aware that EPUB is basically HTML with a little CSS, and that InDesign converts all its paragraph and character styles to CSS classes. For example, if you have a paragraph style called “para intro” then the exported xhtml file is written as <p class=”para-intro”>. ?Similarly, character styles (even if they’re used inside nested or grep styles) are converted into span classes:


So if paragraph and character styles should be converted, then why not object styles, too? Indeed, they are: object styles applied to a frame get converted into DIV classes in the xhtml, and are added to the CSS file, too.

This turns out to be very helpful when formatting images and captions, for example. You can group an image and a caption together and give the group an object style. The object style doesn’t have to look like anything in InDesign (it could be “empty” in its definition), but when you export the EPUB file and crack it open, you’ll see the div class. Here’s the xhtml file from an InDesign document in which I had applied the “imagewrap” object style to a group, and made that group inline where I wanted it in the story:


Note that each object inside the group is given its own div tag, and you end up with two different divs (one for the generic group, and one for the object style). Why? Because InDesign is trying to make sure you have to work hard. I don’t know; seems like a bug to me. So when you’re cleaning up the xhtml files (you almost always have to), you can remove the extra div and tags, to ensure that this is a single div:


Here is what the EPUB looks like with the figure and the caption appearing between the paragraphs:


Now you can style your group in the .css file. For example, in this case, I’ll change the “image-wrap” class to force a wrap (float) with a background color:


The result is dramatically different:


Object styles can be used in all kinds of ways to help speed up the process of formatting your EPUB documents.

David Blatner

David Blatner

David Blatner is the co-founder of the Creative Publishing Network, InDesign Magazine, and the author or co-author of 15 books, including Real World InDesign. His InDesign videos at are among the most watched InDesign training in the world. You can find more about David at
David Blatner

Latest posts by David Blatner (see all)

  • - November 30, -0001
Related Articles

18 Comments on “InDesign Object Styles Convert to DIV classes in EPUB Export

  1. This is great info, David. One question: what’s the trick to getting formatting that came from a nested style to appear as a span? No matter how I try it, it gets ignored.

    I was planning to use In-Tools’ script to make nested character styles explicit to overcome this issue.

  2. @Mike : you have to reformat all the text strings formatted as Nested Styles by manually reapplying Character Styles. So F/C or script.

  3. @Dave : it is not a bug but a feature. DIV are added within the group/DIV to give you more control on the formatting. For instance you can control separately the size of the photo depending the screen resolution and have a better control on text wrapping if you are crazy enough to try to include it in an ePub ;-)

  4. I have a question for all of you exporting ePubs. Have you noticed an increase in the quality of the formatted images exported with the ePub feature in InDesign 7.0.3 released a week ago ?

  5. Here’s the ID Secrets post:

    Harbs’ script can be downloaded from here:

    BTW, I’m in full agreement with Branislav. There’s nothing wrong with with having those DIV tags there. Anything that allows for more formatting freedom is okay by me. In your example there’s only two items in the group. But what if you had a two photos with captions?

    Finally, I think it’s imperative to continually point out to print only designers that they must obtain a working knowledge of HTML and CSS if they want to be able to successfully work with EPUB.

  6. nothing wrong with two div tags. but what about wrapping groups into another div – this would be the most flexible solution:
    <div class=”group”>
    <div class=”image”>
    <div class=”caption”>
    </div class=”group”>

  7. Oy!

    Finding stuff on my site is a daunting task! ;)

    Thanks Bob for pointing out where it was. I have a lot of useful scripts hidden on my site, but it’s like finding a needle in a haystack! :( We’re going to be organizing stuff so you can actually find what you are looking for. Honest! ;)

    (We’re in the process of a site redesign…)

  8. On the issue of two divs instead of one, I actually find that it is giving me less control in the CSS, not more. For example, if I want an image and caption to always remain together, I want to apply page-break-inside:avoid; or inline:block; to the named object style class rather than to the generic “group” class, which every group is tagged with. But if the image and caption are in separate divs, then those attributes will not keep them together because the image caption div closes and a new div (albeit with the same class) opens up for the caption.

    I’m fairly well-versed in CSS, but I don’t consider myself a true expert in it. Maybe there is something I am missing.

    This is a crucial aspect of what I have been facing in creating EPUBs from our books. If someone could address this issue (I know we are going off point from the original point somewhat), that would be very helpful.

  9. This has been immensely helpful, thank you!! I am currently working on an ebook with about 120 images, most with captions, and this post was the final piece of the puzzle to display them properly. I am learning a lot!

    Senthilnathaswami also had an interesting point about keeping the image and caption together using either one or separate divs. I’m going to have to experiment with this myself.

  10. I’ve been using this great trick for years to create custom pull-quotes. Now, with InDesign CC (ID7) the export forces any object to rasterize into an image. Yikes! If anyone discovers a workaround, you’ll be my hero.

  11. For CC, any inline anchored object becomes rasterized when you output it. If it’s a text frame you’ll get a warning alert that it’s going to be rasterized. (You get the alert when you export it.) They did this to output standards-compliant HTML/CSS.

    The solution for CC is to change those anchored frames to above-line or custom. If you used an object style, it’s easy to do this by editing the object style.

  12. When I export to epub InDesign CC adds an extra to the I created in the objectstyle:

    It complicates the formatting I`ve made in the css-class “div.ill”. Is there any way to avoid this?

  13. Sorre, the <> dispapeared:

    When I export to epub InDesign CC adds an extra <> to the <> I created in the objectstyle:


    It complicates the formatting I`ve made in the css-class “div.ill”. Is there any way to avoid this?

  14. Might be better to take a screen shot of what ID’s export code looks like and how you need it to look … but in general, no, there’s really no way to stop ID from adding tags where it thinks it needs to.

    How does it mess up your CSS?

Leave a Reply

Your email address will not be published. Required fields are marked *