# Theme Toggle for BPMN Viewer / Modeler in React Application

**URL:** <https://forum.bpmn.io/t/theme-toggle-for-bpmn-viewer-modeler-in-react-application/7179>\
**Category:** Developers\
**Created:** [February 9, 2022, 3:28am UTC](https://forum.bpmn.io/t/theme-toggle-for-bpmn-viewer-modeler-in-react-application/7179 "2022-02-09T03:28:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pookni](https://forum.bpmn.io/letter_avatar_proxy/v4/letter/p/71e660/32.png) [@pookni](https://forum.bpmn.io/u/pookni)\
**Post date:** [February 9, 2022, 3:28am UTC](https://forum.bpmn.io/t/theme-toggle-for-bpmn-viewer-modeler-in-react-application/7179/1 "2022-02-09T03:28:33Z")

</div>

Hi,

I’m attempting to integrate the BPMN Viewer (and eventually the Modeler) in a React application where I need to support both a light and dark theme that can be toggled by users.

I’m able to set the default fill and stroke colors when creating the Viewer. However, all of my attempts so far to update these colors when the theme changes have failed. More specifically, the bpmnRenderer or defaultFillColor / defaultStrokeColor are always undefined when I attempt an update.

You can find an example of one attempted approach here:

> **[bpmnjs\_theme - CodeSandbox](https://codesandbox.io/s/bpmnjs-theme-pyoef?file=%2Fsrc%2FApp.js)**
>
> bpmnjs\_theme by pookni using bpmn-js, react, react-dom, react-scripts

Does anyone know how to go about accessing / updating these properties? Or would there be a better approach altogether for this use case?

Thanks for any advice.

---

<div class="post-metadata">

**Author:** ![beatriz.mendes](https://forum.bpmn.io/user_avatar/forum.bpmn.io/beatriz.mendes/32/3095_2.png) [@beatriz.mendes](https://forum.bpmn.io/u/beatriz.mendes)\
**Post date:** [February 9, 2022, 12:07pm UTC](https://forum.bpmn.io/t/theme-toggle-for-bpmn-viewer-modeler-in-react-application/7179/2 "2022-02-09T12:07:58Z")

</div>

Hello @pookni,

At the moment, it is not possible to change the default colors of the diagram after its creation.

You can tackle the light/dark mode on your side by using the `defaultFillColor` and `defaultStrokeColor` properties together with CSS operations.

Alternatively, you can use `modeling.setColor` to set the color of shapes (eg.: [here](https://github.com/bpmn-io/bpmn-js/blob/50ed07966f37e6364045db44c9bc9a09a71c40cf/lib/features/editor-actions/BpmnEditorActions.js#L130)):

```javascript
const modeling = modeler.get('modeling');
modeling.setColor(shapes, {
     fill,
     stroke,
});

```

---

<div class="post-metadata">

**Author:** ![Martin](https://forum.bpmn.io/letter_avatar_proxy/v4/letter/m/73ab20/32.png) [@Martin](https://forum.bpmn.io/u/Martin)\
**Post date:** [February 9, 2022, 1:14pm UTC](https://forum.bpmn.io/t/theme-toggle-for-bpmn-viewer-modeler-in-react-application/7179/3 "2022-02-09T13:14:30Z")

</div>

> defaultFillColor / defaultStrokeColor are always undefined when I attempt an update

these values are not public variables and can’t be accessed during runtime.

> <https://github.com/bpmn-io/bpmn-js/blob/4f94ab10f8fdd6d455abaf4971babc90b6c1f9c2/lib/draw/BpmnRenderer.js#L76-L78>

Currently, the only way to modify them is to re-render the viewer when the theme changes. This has some side effects, like resetting the viewport, but those can be cached and reset with `canvas.viewbox()` on the rerender.

here is an example of re-rendering the Viewer on theme change:

> **[bpmnjs\_theme (forked) - CodeSandbox](https://codesandbox.io/s/bpmnjs-theme-forked-8o2p0?file=%2Fsrc%2FApp.js)**
>
> bpmnjs\_theme (forked) using bpmn-js, react, react-dom, react-scripts

---

<div class="post-metadata">

**Author:** ![pookni](https://forum.bpmn.io/letter_avatar_proxy/v4/letter/p/71e660/32.png) [@pookni](https://forum.bpmn.io/u/pookni)\
**Post date:** [February 10, 2022, 3:03am UTC](https://forum.bpmn.io/t/theme-toggle-for-bpmn-viewer-modeler-in-react-application/7179/4 "2022-02-10T03:03:35Z")

</div>

Thank you both for the insight. It’s very much appreciated.

I’ve updated my initial CodeSandbox link with the above solution + my attempt to cache and reset the viewbox to avoid repositioning the diagram on rerender. It seems to be working, so hopefully I have done that part decently well.

Thanks again!

---

<div class="post-metadata">

**Author:** ![nikku](https://forum.bpmn.io/user_avatar/forum.bpmn.io/nikku/32/5130_2.png) [@nikku](https://forum.bpmn.io/u/nikku)\
**Post date:** [July 22, 2025, 3:41pm UTC](https://forum.bpmn.io/t/theme-toggle-for-bpmn-viewer-modeler-in-react-application/7179/5 "2025-07-22T15:41:58Z")

</div>

Closed on July 22, 2025, 3:41pm UTC


