CSS Cleanup

CSS Cleanup removes common publisher, conversion, and device-specific stylesheet cruft from EPUB CSS files. It can process the current CSS file or all stylesheet files in the book.

Current file or whole book

Use the toolbar menu to choose whether to clean only the current CSS file or every stylesheet in the book. Whole-book cleanup is useful after conversion, but review the diff before accepting broad changes.

Fonts

If a font-family declaration lists only named fonts and no generic family, the whole declaration is removed rather than left empty. The text then falls back to the reader's default, which is usually the intended result, but it is a larger change than it may appear in the diff.

Only font files stored inside the book are candidates for deletion. Fonts loaded from a web address, or embedded directly in the stylesheet as data, are left in place.

Publisher and vendor CSS

Some EPUBs can contain custom CSS declarations that have no meaning for most ebook software. Use this to remove Adobe and vendor-specific declarations.

Colors

Explicit colors are often irrelevant on grayscale e-ink devices and may reduce contrast. The color options can remove explicit text and background colors while preserving behavioral or theme-friendly values.

The following values are preserved: inherit, currentColor, transparent, initial, unset, revert, and CSS variables such as var(--text-color). Related properties such as border-color are not removed by these options.

Custom CSS properties

The custom property option removes declarations whose property names match a comma-separated list. The default list is line-height, font-variant-*, but the option is disabled by default.

Simple * wildcards are supported, for example font-*, page-break-*, and -epub-*. This removes declarations only; empty selectors can be removed afterward with Remove empty CSS rules after cleanup.

Unit conversion

CSS Cleanup can convert selected print-oriented units to em values:

These conversions are useful for CSS created from print layouts. They should still be reviewed, especially when measurements are used for layout rather than text spacing.

The conversion applies one fixed ratio per unit and rounds the result, rather than working out what em represents in each individual rule. It produces a sensible starting value, not an exact visual match, so margins and indents are worth checking after conversion.

Remove empty CSS rules

After other cleanup operations, selectors may become empty. This option removes rules with no remaining declarations. It is useful after vendor-property or color cleanup.

Comments are left alone, including a comment sitting immediately before an empty rule, and a rule whose only remaining content is a comment. Licence and copyright notices in a stylesheet therefore survive.

What is left alone

A few things are never treated as active stylesheet content:

A suggested order

For a converted or publisher EPUB, this order usually gives the cleanest result:

  1. Remove embedded @font-face rules and named font families, with font-file deletion enabled.
  2. Remove Adobe and vendor-prefixed properties.
  3. Remove explicit colors.
  4. Remove any custom properties you want gone, such as line-height and font-variant-*.
  5. Convert print units, then check the diff before continuing.
  6. Remove empty rules.

All of these can be selected in a single run; the order above simply reflects how their effects build on each other.

Safety

CSS cleanup edits stylesheets directly. The tool creates a savepoint before processing and can show Calibre's diff afterward. Review both changed CSS files and any deleted font files before publication — a deleted font is the one change the diff viewer will not show you.