---
source: https://carbone.io/documentation/design/advanced-features/colors.html
title: "Applying dynamic colors to elements (text, row, cell, ...)"
description: "Applying dynamic colors to elements (text, row, cell, ...)"
generated_at: "2026-07-13"
---

# Colors

Applying dynamic colors to elements (text, row, cell, ...)  
ENTERPRISE FEATURE Available for:  
✓ Carbone Cloud  
✓ Carbone On-premise  
✗ Embedded Carbone JS   v4.0+ 

## :color(scope, type)

v4.17.0+

Apply the color on the text, paragraph, table row or table cell

| Params | Description | Type |
| --- | --- | --- |
| scope | Specifies the element to be color-changed   \- `p` : the current paragraph where the tag is (by default)   \- `cell` : the current cell of a table   \- `row` : the current row of a table   \- `shape` : the current shape   \- `part` : for text section (the color is applied within the same styled of the element) | String |
| type | Defines the property to be modified.   \- `text` for the text color (by default)   \- `highlight` to highlight the text   \- `background` for cells, rows and shapes   \- `border` for shapes only | String |

**Important Notes:**

> ℹ️ **Note:** Compatible with PDF, ODT, ODP, DOCX, PPTX, HTML files.

-   The color provided must be in 6-digit hex color notation, with or without a hashtag, and can be in lowercase or uppercase: `#FF0000` or `FF0000`. Carbone replaces incorrect color values with light gray (`#888888`).
-   The `:color` formatter manages priority between overlapping areas. A color applied to the current paragraph has a higher priority than a color applied to the current shape, cell, or row.
-   For HTML, the color is applied using the `style` attribute only to the selected HTML tag (`tr`, `td`, `p`).
-   For ODP (text, tables, and shapes) and ODT (shapes only), the `:color` formatter requires that a non-default style is already applied to the target element in the template (e.g., a custom text color).
-   For PPTX, all combinations of `type` (`background`, `text`, `border`) and `scope` (`row`, `cell`, `shape`) are supported, except `border` which applies only to shapes. Available since v5.6.0.
-   Complex nested tables with colors on sub-tables are not fully supported.
-   `highlight` is not managed in DOCX templates.
-   The `:color` formatter cannot be used in aliases and cannot be combined with aggregators.
-   The `:color(part)` feature is currently available only for ODT templates.

Get inspired by one of our real-life examples: [Invoice](/examples/invoice-simple/index.md) or [Sensor Readings](/examples/sensor-readings/index.md)

## Simple text color

The following example changes the text color to red:

```cdata
{
  "flowerColor": "#FF0000"
}
```

```ctemplate
Color of roses {d.flowerColor:color(p)}
This paragraph is not colored.
```

```cresult
Color of roses 
This paragraph is not colored.
```

## Condition and color

The following example changes the text color based on a condition.

Details:

-   If the `test` value is equal to "OK," the text color will be `d.success` (color "#007700").
-   If the `test` value is not equal to "OK," the text color will be `d.error` (color "#FF0000").
-   The `:color(p)` formatter applies the color to the text in the current paragraph.

```cdata
{
  "test"      : "OK",
  "testError" : "ERROR",
  "success"   : "#007700",
  "error"     : "#FF0000"
}
```

```ctemplate
The assessment passed
{d.test:ifEQ(OK):show(.success):elseShow(.error):color(p)}
Error color
{d.testError:ifEQ(OK):show(.success):elseShow(.error):color(p)}
```

```cresult
The assessment passed
Error color
```

## Loop and color

The example conditionally changes the text color of the current table row.

In the following example, the Carbone tag `{d.tests[i].result:ifEQ(ok):show(#007700):elseShow(d.error):color(row, text)}` is used in the template:

-   If the `result` value is equal to "ok," the text color will change to green (`#007700`). The argument passed is a string, not a value sourced from the JSON.
-   If the `result` value is not equal to "ok," the color will be `d.error`.
-   The `:color(row, text)` formatter changes the text color in the current row.

```cdata
{
  "error": "#FF0000",
  "tests": [
    { "name": "Security Training","result": "ok" },
    { "name": "Code Auditing","result": "20 Vulnerabilities found" },
    { "name": "Firewall Testing","result": "ok" }
  ]
}
```

**Template:**

| Test | info |
| --- | --- |
| {d.tests[i].name} | {d.tests[i].result} {d.tests[i].result:ifEQ(ok):show(#007700):elseShow(d.error):color(row, text)} |
| {d.tests[i+1]} |   |

```cresult
TestinfoSecurity Trainingok Code Auditing20 Vulnerabilities found Firewall Testingok 
```

## Combined colors

The example conditionally changes the background color and text color of the table row.

Two tags are used in the following template:

-   `{d.tests[i].result:ifEQ(ok):show(#000000):elseShow(#FFFFFF):color(row, text)}`: If `result` is equal to `ok`, the text color of the current row is changed to black (`#000000`); otherwise, it changes to white (`#FFFFFF`).
-   `{d.tests[i].result:ifEQ(ok):show(#FFFFFF):elseShow(d.error):color(row, background)}`: If `result` is equal to `ok`, the row keeps a white background (`#FFFFFF`); otherwise, it takes the red color sourced from the JSON (`d.error`).

```cdata
{
  "error": "#ffd9d9",
  "tests": [
    { "name": "Security Training","result": "ok" },
    { "name": "Code Auditing","result": "20 Vulnerabilities found" },
    { "name": "Firewall Testing","result": "ok" }
  ]
}
```

**Template:**

| Test | id |
| --- | --- |
| {d.tests[i].name} | {d.tests[i].result} {d.tests[i].result:ifEQ(ok):show(#000000):elseShow(#d90000):color(row, text)} {d.tests[i].result:ifEQ(ok):show(#FFFFFF):elseShow(d.error):color(row, background)} |
| {d.tests[i+1]} |   |

```cresult
TestidSecurity Trainingok  Code Auditing20 Vulnerabilities found  Firewall Testingok  
```

## Color Text Section

> ℹ️ **Note:** Compatible with PDF and ODT files for the moment.

The `:color` formatter includes a **part** argument, which allows you to apply color to a specific section within a paragraph. This feature is particularly useful when you need to highlight certain parts of your text without affecting the entire paragraph.

To correctly use the `:color(part)` formatter, follow these steps:

1.  **Tag Placement**: Place the tag with the `:color(part)` formatter right next to the text you want to color.
2.  **Selecting Tags**: In LibreOffice or MS Word, select the tags you want to color, including the tag containing the `:color(part)` formatter.
3.  **Clear Style** : Click on the "Clear Direct Formatting" icon located in the "Home" tab. This will define the section to be colored for the `:color(part)` formatter.
4.  **Reapply Font Style**: If you had a specific font style, reapply it after clearing the direct formatting.

## Color replacement {bindColor}

> ⚠️ **Warning:** We recommend using the [`:color`](#color-scope-type) formatter instead of `{bindColor}` because it is much simpler to use and less error-prone. `{bindColor}` was the old method in Carbone for managing color.

> ℹ️ **Note:** Compatible with PDF, ODT, ODP, DOCX, and ODS files.

The special `bindColor` tag allows you to replace a color reference in the template with a new color from your JSON dataset. Usage:

`{bindColor(myColorToBind, myFormat) = d.myVar}`

-   `myColorToBind`: A temporary hexadecimal color applied to text, background, or a cell background. It is used by Carbone to identify the color to replace. The hexadecimal value is case-insensitive, and the hashtag at the beginning is optional. Note an exception regarding [dynamic background colors on MS Word DOCX documents](#color-replacement-bindcolor-microsoft-word-exception-for-bindcolor).
-   `myFormat`: The format of the new color expected from the `d.myVar` tag. Here is a list of available [color formats](#color-replacement-bindcolor-color-formats-for-bindcolor).
-   `d.myVar`: The tag that corresponds to the new color.

Unlike regular tags, `{bindColor()}` can be placed anywhere in the document, such as the header, footer, or below a repetition `[i+1]`, even if the `myVar` argument is part of a repetition.

For more details, refer to [the example below](#color-replacement-bindcolor-simple-example-with-bindcolor).

**Important Notes:**

Supported on:

-   Text and background colors
-   Table cell backgrounds
-   Shape backgrounds and line colors for **DOCX only**. Write the `bindColor` tag in the document body, not in the alternative text of shapes. The replaced color format must be `RGB` only.

### Simple example with {bindColor}

> ⚠️ **Warning:** We recommend using the [`:color`](#color-scope-type) formatter instead

**Data**

```json
{
  "color": "#FF0000", // red
  "color2": "#00FF00", // green
  "color3": "#0000FF" // blue
}
```

**Template**

![Basic dynamic color](/img/doc/dynamic-color-1.png)

**Details:**

-   `Manage` gets the `#00FFFF` reference color and will be replaced by `#FF0000` coming from the `{d.color}` tag.
-   `dynamic` gets the `#FF00FF` reference color and will be replaced by `#00FF00` coming from the `{d.color2}` tag.
-   `color` gets in background the reference color `#0000FF` and will be replaced by `#00FF00` coming from the `{d.color3}` tag.

**Result**

![Basic dynamic color result](/img/doc/dynamic-color-1-result.png)

### Color formats for {bindColor}

> ⚠️ **Warning:** We recommend using the [`:color`](#color-scope-type) formatter instead

There are 5 color formats:

-   `#hexa`:
    
    ```json
    {
      "color": "#FF0000"
    }
    ```
    
-   `hexa`:
    
    ```json
    {
      "color": "FF0000"
    }
    ```
    
-   `color`:
    
    ```json
    {
      "color": "red"
    }
    ```
    
-   `rgb`:
    
    ```json
    {
      "color": {
        "r": 255, // Between 0 and 255
        "g": 0, // Between 0 and 255
        "b": 0 // Between 0 and 255
      }
    }
    ```
    
-   `hsl`:
    
    ```json
    {
      "color": {
        "h": 300, // Between 0 and 360
        "s": 50, // Between 0 and 100 or 0 and 1
        "l": 50 // Between 0 and 100 or 0 and 1
      }
    }
    ```
    

### Microsoft Word exception for {bindColor}

> ⚠️ **Warning:** We recommend using the [`:color`](#color-scope-type) formatter instead

In Microsoft Word, only a **color name** can be used to replace the **background** color of a text.  
17 colors are available, which are:

```text
yellow    | green     | cyan      | magenta   | blue | red
darkBlue  | darkCyan  | darkGreen | darkMagenta |  darkRed | darkYellow
darkGray  | lightGray | black     | white     | transparent
```

You can still use hexadecimal colors for the **text** and **cell backgrounds** on Microsoft Word.

**Data**

```json
{
  "color": "darkYellow",
  "color2": "green",
  "color3": "11BBCC"
}
```

**Template**

`Microsoft` gets in background the `red` color, `Word` gets in background the `magenta` color and `background` gets the `#FFFF00` color

![Word color exception](/img/doc/dynamic-color-2.png)

**Result**

![Word color exception result](/img/doc/dynamic-color-2-result.png)

### Loop with {bindColor}

> ⚠️ **Warning:** We recommend using the [`:color`](#color-scope-type) formatter instead

Each line in a table can be colorized by one color:

**Data**

```json
{
  "user": [
    {
      "firstname": "Jean",
      "lastname": "Dujardin",
      "color": { "r": 255, "g": 0, "b": 0 }
    },
    {
      "firstname": "Omar",
      "lastname": "Sy",
      "color": { "r": 0, "g": 255, "b": 0 }
    }
  ]
}
```

**Template**

The first line gets the `#0000FF` color and the second line gets the `#00FFFF` color. Each line gets the color corresponding to the color key in each user object.

![Table color](/img/doc/dynamic-color-table.png)

**Result**

![Table color result](/img/doc/dynamic-color-table-result.png)

## Related topics

- [Translations i18n](/documentation/design/advanced-features/translations-i18n.md)
- [Transform](/documentation/design/advanced-features/transform.md)
- [Digital signatures](/documentation/design/advanced-features/signatures.md)
- [Pictures](/documentation/design/advanced-features/pictures.md)
- [Pagination](/documentation/design/advanced-features/pagination.md)
- [Key-value mapping](/documentation/design/advanced-features/key-value-mapping.md)
