# How to add color to BPMN diagram for dynamic XML

**URL:** <https://forum.bpmn.io/t/how-to-add-color-to-bpmn-diagram-for-dynamic-xml/5269>\
**Category:** Modeler\
**Created:** [October 7, 2020, 6:36am UTC](https://forum.bpmn.io/t/how-to-add-color-to-bpmn-diagram-for-dynamic-xml/5269 "2020-10-07T06:36:36Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sathiyamoorthy](https://forum.bpmn.io/letter_avatar_proxy/v4/letter/s/f9ae1b/32.png) [@sathiyamoorthy](https://forum.bpmn.io/u/sathiyamoorthy)\
**Post date:** [October 7, 2020, 6:36am UTC](https://forum.bpmn.io/t/how-to-add-color-to-bpmn-diagram-for-dynamic-xml/5269/1 "2020-10-07T06:36:36Z")

</div>

I’m trying to add color to my task created in BPMN.js and below mentioned are the scenario.

1. I’m getting XML from backend to create BPMN diagram and i need to show the status of task in some color based on status like(red,green,blue etc…) in my UI. Am appending classname attribute in my XML against the particular task to add CSS for the added classname. But the classname was not appending in my DOM element.

\<?xml version="1.0" encoding="UTF-8"?\>

```
        <bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" id="Definitions_0xcv3nk" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.0.0-dev">
        <bpmn:process id="Process_0sckl64" isExecutable="true">
        <bpmn:startEvent id="StartEvent_1" className="taskstatus" />
        </bpmn:process>
        <bpmndi:BPMNDiagram id="BPMNDiagram_1">
        <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0sckl64">
        <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
        <dc:Bounds x="179" y="159" width="36" height="36" />
        </bpmndi:BPMNShape>
        </bpmndi:BPMNPlane>
        </bpmndi:BPMNDiagram>
        </bpmn:definitions>
```

---

<div class="post-metadata">

**Author:** ![Niklas\_Kiefer](https://forum.bpmn.io/user_avatar/forum.bpmn.io/niklas_kiefer/32/3882_2.png) [@Niklas\_Kiefer](https://forum.bpmn.io/u/Niklas_Kiefer)\
**Post date:** [October 7, 2020, 11:17am UTC](https://forum.bpmn.io/t/how-to-add-color-to-bpmn-diagram-for-dynamic-xml/5269/2 "2020-10-07T11:17:34Z")

</div>

Adding classNames won’t work, since this is not valid BPMN 2.0 XML.

The visual definition of shapes are inside the `bpmndi` part of the XML. The bpmn-js Modeler will then handle those accordingly. As an example

```xml
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:bioc="http://bpmn.io/schema/bpmn/biocolor/1.0" id="Definitions_17576rk" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.3.0-nightly.20200929">
  <bpmn:process id="Process_0dujmh1">
    <bpmn:startEvent id="StartEvent_1" />
  </bpmn:process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0dujmh1">
      <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1" bioc:stroke="rgb(67, 160, 71)" bioc:fill="rgb(200, 230, 201)">
        <dc:Bounds x="179" y="79" width="36" height="36" />
      </bpmndi:BPMNShape>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>

```

Note the `bioc:stroke` and `bioc:fill` properties in the `bpmndi:BPMNShape` element.

You can use [this sandbox](https://codesandbox.io/s/colors-mr9w4?file=/src/diagram.bpmn) to see how this will be rendered in the Modeler.

---

<div class="post-metadata">

**Author:** ![sathiyamoorthy](https://forum.bpmn.io/letter_avatar_proxy/v4/letter/s/f9ae1b/32.png) [@sathiyamoorthy](https://forum.bpmn.io/u/sathiyamoorthy)\
**Post date:** [October 7, 2020, 5:47pm UTC](https://forum.bpmn.io/t/how-to-add-color-to-bpmn-diagram-for-dynamic-xml/5269/3 "2020-10-07T17:47:43Z")

</div>

Thanks Niklas,

I have understood your comments. But i want to set color based on task status like (COMPLETED,FAILURE,INPROGRESS).

1. Status of created task will come from backend.  
For Example: I have created one task in BPMN and passed the created XML to backend. In backend the status of task is checked in DATABASE. If the status of task is COMPLETED then i need to show in GREEN color. Then if the status is FAILURE i need to show in RED color.

How to send the task status in XML and based on status how to change color?

---

<div class="post-metadata">

**Author:** ![Niklas\_Kiefer](https://forum.bpmn.io/user_avatar/forum.bpmn.io/niklas_kiefer/32/3882_2.png) [@Niklas\_Kiefer](https://forum.bpmn.io/u/Niklas_Kiefer)\
**Post date:** [October 7, 2020, 6:32pm UTC](https://forum.bpmn.io/t/how-to-add-color-to-bpmn-diagram-for-dynamic-xml/5269/4 "2020-10-07T18:32:52Z")

</div>

This would technically possible via [custom element properties](https://github.com/bpmn-io/bpmn-js-example-custom-elements#creating-a-model-extension) and then [render your element based on this property](https://github.com/bpmn-io/bpmn-js-example-custom-elements#creating-custom-rendering).

However, another solution in your case would be so set the `bioc:stroke` and `bioc:fill` properties in the backend based on the task status you get from the database. If you anyway set contents to the XML (task status), why not then directly set the color in the di information?

Then you would always get valid BPMN XML from the backend with the correct color and the Modeler would always display it. That would be a cleaner, and BPMN 2.0 compliant in my opinion.

---

<div class="post-metadata">

**Author:** ![sathiyamoorthy](https://forum.bpmn.io/letter_avatar_proxy/v4/letter/s/f9ae1b/32.png) [@sathiyamoorthy](https://forum.bpmn.io/u/sathiyamoorthy)\
**Post date:** [October 8, 2020, 5:40am UTC](https://forum.bpmn.io/t/how-to-add-color-to-bpmn-diagram-for-dynamic-xml/5269/5 "2020-10-08T05:40:39Z")

</div>

Thanks Niklas,

Your solution is working.

---

<div class="post-metadata">

**Author:** ![Arunkumar](https://forum.bpmn.io/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@Arunkumar](https://forum.bpmn.io/u/Arunkumar)\
**Post date:** [October 12, 2020, 11:01am UTC](https://forum.bpmn.io/t/how-to-add-color-to-bpmn-diagram-for-dynamic-xml/5269/6 "2020-10-12T11:01:34Z")

</div>

Niklas,

Thanks for letting us know to set the `bioc:stroke` and `bioc:fill` properties in backend.

Is there any way that we can add these properties to the already generated BPMN xml in backend. I mean is there any java code to do that.

---

<div class="post-metadata">

**Author:** ![Niklas\_Kiefer](https://forum.bpmn.io/user_avatar/forum.bpmn.io/niklas_kiefer/32/3882_2.png) [@Niklas\_Kiefer](https://forum.bpmn.io/u/Niklas_Kiefer)\
**Post date:** [October 12, 2020, 12:18pm UTC](https://forum.bpmn.io/t/how-to-add-color-to-bpmn-diagram-for-dynamic-xml/5269/7 "2020-10-12T12:18:43Z")

</div>

This should be possible. There are for sure some XML parsing libraries for Java out there who can do it, e.g. [https://github.com/camunda/camunda-bpm-platform/tree/master/model-api/bpmn-model](https://github.com/camunda/camunda-bpm-platform/tree/master/model-api/bpmn-model)

But I’m not a Java expert. It’s also not related to [bpmn.io](http://bpmn.io)

---

<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:34pm UTC](https://forum.bpmn.io/t/how-to-add-color-to-bpmn-diagram-for-dynamic-xml/5269/8 "2025-07-22T15:34:51Z")

</div>

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


