Changing themes & colors using JavaScript

You can change the color theme by either using an API or providing a path to a custom CSS file in the constructor.

Apryse Docs Image

Setting WebViewer constructor CSS option

The CSS option allows you to set a css file path while instantiating WebViewer. It's great if you have an external stylesheet file, for example.

Example

JavaScript

1WebViewer({
2 licenseKey: 'YOUR_LICENSE_KEY',
3 path: 'lib',
4 css: 'path/to/stylesheet.css'
5}, document.getElementById('viewer'));

Using setTheme API

The API allows you to change the theme to another pre-defined theme on the fly. See setTheme for details.

Override CSS variables

Another option is to override CSS color variables. Just like changing the theme, this can be done on the fly (without re-instantiating WebViewer).

Example

1WebViewer({
2 licenseKey: 'YOUR_LICENSE_KEY',
3 path: 'lib',
4}, document.getElementById('viewer')).then(instance => {
5 const style = instance.UI.iframeWindow.document.documentElement.style;
6 style.setProperty(`--primary-button`, 'red');
7 style.setProperty(`--primary-button-hover`, 'yellow');
8});

You can find the default css variables for both light theme and dark theme in the github repository.

Other properties

See the customizing styles for more information about customizing other properties.

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales