WebViewer UI background color, without separate CSS asset

WebViewer Version: 10.9.0

Do you have an issue with a specific file(s)? No
Can you reproduce using one of our samples or online demos? Yes
Are you using the WebViewer server? No
Does the issue only happen on certain browsers? No
Is your issue related to a front-end framework? No
Is your issue related to annotations? No

Please give a brief summary of your issue:
(Think of this as an email subject)
I just want to change the background color of the “documentContainer.”

Please describe your issue and provide steps to reproduce it:
(The more descriptive your answer, the faster we are able to help you)
Ultimately, I just want to specify the background color of the “document container” element. This is the element with a class “DocumentContainer” and data element “documentContainer.”

I understand that after reading your documentation on customizing the WebViewer UI that there are a couple ways to approach this. One is to have a CSS asset served separately and specify the path in the WebViewer constructor.

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

I tried this out and it works, but for the simple goal of just changing the background color, this is more setup than I would like.

The other approach in your guide suggests accessing the DOM directly:

const element = instance.UI.iframeWindow.document;
// ...

But I also noticed the setStyle API in your guide. Is the document container accessible using your “Modular UI?” If so, I’m hoping it’s possible to do some variant of the examples I’m seeing instead. Something like:

instance.UI.getDocumentContainer().setStyle({ backgroundColor: "tomato" });

Is such a “component” for the document container accessible like this, or is accessing the DOM really the only option?

Please provide a link to a minimal sample where the issue is reproducible:
Not applicable.

Hello, I’m AiRon, an automated tech support bot :robot:
While you wait for one of our customer support representatives, I can help you with your question.


Changing the background color of the “documentContainer” in WebViewer without using a separate CSS file can be achieved by directly manipulating the DOM or using the WebViewer APIs. The setStyle API is indeed a convenient way to apply styles, but it is not directly available for the document container component. Instead, you can use JavaScript to access and modify the styles of the document container directly.

Some things you can try:

  • Use the instance.UI.iframeWindow.document to access the document container and change its background color directly.

  • Access the document container using JavaScript and apply the style changes like so:
    instance.UI.iframeWindow.document.querySelector('.DocumentContainer').style.backgroundColor = 'tomato';

  • Ensure that your code runs after the WebViewer has fully initialized to avoid any timing issues.



Here are some resources that might help you:


Hopefully, this helps you solve your problem while you wait for a human to get back to you.

Hello @jamesl,

Thank you for posting on our forum,

setStyle is only applicable to Item components based on our Modular UI (Modular UI is default in Version 11, but manually set in Version 10, see here for example, instead of ‘legacy’ use ‘beta’).

Items include single components such as Tool Buttons, Ribbon Buttons, or Preset Control Buttons (Zoom, Rotate Page, etc.). This would not include the container of the viewer.

If the CSS method does not work for you, we would definitely recommend the modifying the style of the DOM element itself, as it would be the most straightforward approach. Let us know if you need further clarification.

Best Regards,
Jacob Romano Carlsen
Web Development Support Engineer
Apryse Software Inc.