Skip to content
React PDF Viewer

Search

Theming

Match the viewer to your design with CSS variables, dark and automatic presets, and state-based styling.

Set CSS variables

Every color, size and spacing value in the viewer is a CSS variable. Set them on the viewer (style or className) or on any ancestor, so a whole section of your app can share one theme.

The most useful variables:

VariableControls
--rpv-toolbar-bg, --rpv-toolbar-fgToolbar colors
--rpv-accentFocus outlines, the current thumbnail, progress
--rpv-toolbar-radius, --rpv-button-size, --rpv-icon-sizeToolbar shape and sizes
--rpv-page-bg, --rpv-page-border, --rpv-page-radius, --rpv-page-shadowThe page frame
--rpv-viewport-max-width, --rpv-viewport-min-height, --rpv-viewport-max-heightThe document area
--rpv-font-familyViewer text (inherits by default)

All 54 variables, with their default values, are generated from the stylesheet in the CSS variables reference.

Dark mode

className="rpv-theme-dark" applies the dark preset. className="rpv-theme-auto" applies it only when the operating system prefers a dark color scheme.

The values each preset sets are in the rpv-theme-dark and rpv-theme-auto references. If your app has its own dark-mode switch, toggle the class from your theme state, or set the variables yourself inside your dark-mode selector.

State-based styling

The root element (.rpv-root) reflects the viewer’s state as attributes, so CSS can react to it without JavaScript:

AttributePresent or value
data-statusidle, loading, ready or error
data-layoutsingle or continuous
data-compactbelow compactBreakpoint
data-fullscreenin fullscreen, in any mode
data-presentationlayout, native or overlay
data-zoomedwhile zoomed above defaultScale

The attributes are generated from the component source in the PdfViewer reference.

Fonts

The viewer inherits your page’s font. Set --rpv-font-family to use a different one for viewer text. Page content always uses the fonts embedded in the PDF.