CSS Print

From XPUB & Lens-Based wiki

CSS

Cascading Style Sheets

body{
    background-color: pink;
    color: green;
    margin: 100px;
}

CSS1, CSS2.1, CSS3

Screenshot from 2023-10-03 15-11-04.png

Screenshot of one of the slides from Julie Blanc, as part of her presentation during the Paged.js workshop in October 2022. http://slides.julie-blanc.fr/20221013_xpub-rotterdam.html#/19

CSS Print modules

  • CSS Paged Media Module Level 3
  • CSS Generated Content for Paged Media module
  • CSS Fragmentation Module Level 3
  • CSS Page Floats

CSS Paged Media Module

Paged media have many special requirements for the display of document content, which have evolved over the long history of printed books. Running headers and footers function as aids to navigation. Notes may appear at the bottom of the page, as footnotes. The properties of pages themselves may change based on their content or position in the document. Leaders visually connect related content. Cross-references may require generated text. Some paged media formats such as PDF use bookmarks for navigation.

This module defines new properties and values, so that authors may bring these techniques to paged media.

https://www.w3.org/TR/css-page-3/ (published working draft version)

https://drafts.csswg.org/css-page/ (current latest draft)

CSS Print Community Group

For a couple of years (2020-2023), a group of people formed a W3C community group to provide feedback to the CSS Print specs. Unfortunately this group is closed since Dec 2023.

This was their web page and blog: https://www.w3.org/community/cssprint/

Working with a NOT YET standard

Modern browsers (no CSS Print support yet)

A few of the CSS Print properties are supported by modern (aka up-to-date) browsers, but not many unfortunately, as the W3C CSS Paged Media module is still in a "working draft" mode.

You can check if a CSS property is supported by a specific browser at: https://caniuse.com/

It's good to say that you can still get pretty far with the properties that are supported atm. It really depends on what you want to make in the end.

Paged.js and Weasyprint (already support CSS Print!)

If you nevertheless do want to use these properties, you can use Paged.js, a Javascript library also known as a polyfill, that aims to fill the gaps between the working draft document and modern browsers. The project comes with extended documentation: https://pagedjs.org/documentation/.

Or you can use Weasyprint, who also supports most of the CSS Paged Media properties described on this page. In the Weasyprint documentation here you can read which properties are supported and which ones not.

CSS Print examples

An important proposal of the CSS Print drafts is to add a @page selector, that you can use to style a web page when it is rendered into pages.

@page{
    size: A4 portrait;
    margin: 20mm 30mm;
    bleed: 3mm;
    marks: crop;
}

More examples of CSS Print selectors and properties can be found here: CSS Print examples

CSS Print documentation

also called referred to as "CSS Paged Media"

Media queries: @media print, @media screen

Kiara's great listing of css-print links:

CSS Print tools

Layout engines for CSS Print

Custom workflows made with CSS Print

Books and publications made with CSS Print workflows

Examples, boilerplates, resources

Readings

Online channels

See also