Skip to main content

CSS Media Queries

Below are all of the media queries supported by Prince. For their precise definition please refer to the Media Queries Level 4 specification.

Media queries test how Prince is configured, rather than how the document is styled.

note

The configuration of Prince often depends on the command-line arguments passed to it.

Media Queries​

A Media Query is a method of testing certain aspects of the user agent or device that the document is being displayed in. It is used in the CSS @media at-rule.

The syntax consists of an optional media query modifier, an optional media type, and zero or more media features.

Several media queries can be combined into a comma separated media query list.

@media print and (orientation: portrait) {
...
}
@media screen, print and not(pointer: none) {
...
}

Media Query Modifiers​

Negating a media query

not

An individual media query can be negated by prefixing it with the keyword not.
Hiding a media query from legacy user agents

only

Prefixing a media query with the keyword only will have no effect on the media query's result, but will be ignored by legacy user agents.

Media Types​

A media type is a category of user-agent devices on which a document may be displayed. A more fine-grained way of targeting a specific device's exclusive aspects might be to use media features instead, or in addition. Prince defaults to the media type print.

However, note that the command-line option --media can be used to set a media type that media queries can test against. This can be convenient if the person running Prince knows in advance whether the PDF will be printed or viewed on the screen, such as might be the case for slideshows, or in case one might prefer the author's idea of what screen means.

Media types

all

Matches all devices.

print

Matches printers and devices intended to reproduce or produce a printed display.

screen

Matches all devices that are not matched by print or speech.

speech

Matches screenreaders and other devices that "read out" a page.

Prince allows for arbitrary media types, other than those from the spec - you could e.g. style for an alternative print media type optimized for screen display (rather than physical print on paper), and call for it with the command-line option --media:

Command line
$ prince --media=print-for-screen file.html
CSS
@media print-for-screen {
...
}

However, it is not recommended to use non-standard media types. In most cases a valid and more solid alternative approach would be to query for media features.

Media Features​

A media feature is a more fine-grained way of targeting a specific user-agent. Media features use the same syntax as CSS properties. However, there are some differences between the two:

  • Properties provide information about how to present a document; media features describe requirements of the output device.
  • Media features are wrapped in parentheses, and can be combined into more articulated media conditions.
  • A media feature may be given with only its name to evaluate the feature in a boolean context.
  • Media features with "range" type may be expressed with standard mathematical comparison operators.
  • Properties sometimes accept complex values, while media features only accept single values.

Multiple media features may be combined into a media condition using full boolean algebra (not, and, or).

Media feature types
discreteMedia features of the type "discrete" take their values from a set.
rangeMedia features of the type "range" take their values from a range. Their feature names can be prefixed by min- or max-.

Dimension Media Features​

width

Value: <length>Describes the width of the displayed page.
Type: range

height

Value: <length>Describes the height of the displayed page.
Type: range

aspect-ratio

Value: <length>Describes the ratio of the width to the height of the displayed page.
Type: range

orientation

Value: portrait | landscapeDescribes the width of the displayed page.
Type: discrete

Display Quality Media Features​

resolution

Value: <resolution> | infiniteDescribes the resolution of the output device.
Type: range

scan

Value: interlace | progressiveDescribes the scanning process of the output device. This feature is always false for Prince.
Type: discrete

grid

Value: <boolean>Describes whether the output device is grid (1) or bitmap (0). Prince is bitmap based, and thus 0 matches.
Type: discrete

update

Value: none | slow | fastDescribes the ability of the output device to modify the appearance of the content once it has been rendered. In Prince the layout cannot be updated, and thus only none matches.
Type: discrete

overflow-block

Value: none | scroll | optional-paged | pagedDescribes the behavior of the device when content overflows the initial containing block in the block axis.
Type: discrete

overflow-inline

Value: none | scrollDescribes the behavior of the device when content overflows the initial containing block in the inline axis.
Type: discrete

Color Media Features​

color

Value: <integer>Describes the number of bits per color component of the output device. Prince assumes 13 color bits.
Type: range

color-index

Value: <integer>Describes the number of entries in the color lookup table of the output device.
Type: range

monochrome

Value: <integer>Describes the number of bits per pixel in a monochrome framebuffer.
Type: range

color-gamut

Value: srgb | p3 | rec2020Describes the approximate range of colors that are supported by the output device.
Type: discrete

Interaction Media Features​

pointer, any-pointer

Value: none | coarse | fineDescribes the presence and accuracy of pointing devices. Prince assumes none.
Type: discrete

hover, any-hover

Value: none | hoverDescribes the user's ability to hover over elements on the page. Prince assumes none.
Type: discrete

Scripting Media Features​

scripting

Value: none | initial-only | enabledDescribes whether scripting languages, such as JavaScript, are supported. Prince assumes none or initial-only, depending on its configuration.
Type: discrete

User Preference Media Features​

forced-colors

Value: none | activeDescribes whether the forced-color accessibility feature, intended to increase the readability of text through color contrast, is enabled. Prince assumes none.
Type: discrete

prefers-color-scheme

Value: light | darkDescribes the user’s desire to view a page using a light or dark color theme. Prince assumes light.
Type: discrete