# How to change ion-toolbar background dynamically - Ionic v4

**URL:** <https://forum.ionicframework.com/t/how-to-change-ion-toolbar-background-dynamically-ionic-v4/162745>\
**Category:** Ionic Framework\
**Created:** [April 29, 2019, 11:37pm UTC](https://forum.ionicframework.com/t/how-to-change-ion-toolbar-background-dynamically-ionic-v4/162745 "2019-04-29T23:37:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mathm3](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mathm3/32/125615_2.png) [@mathm3](https://forum.ionicframework.com/u/mathm3)\
**Post date:** [April 29, 2019, 11:37pm UTC](https://forum.ionicframework.com/t/how-to-change-ion-toolbar-background-dynamically-ionic-v4/162745/1 "2019-04-29T23:37:23Z")

</div>

Hello!

I’m trying to change ion-toolbar color dynamically (I get the hexadecimal color from database), but not working.

I tried:

```auto
<ion-toolbar [style.background-color]="customColor"></ion-toolbar>

```

```auto
<ion-toolbar [color]="customColor"></ion-toolbar>

```

The [style.background-color] work with others components. How i change the toolbar color dynamically?  
Thank you!

---

<div class="post-metadata">

**Author:** ![jjdev](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@jjdev](https://forum.ionicframework.com/u/jjdev)\
**Post date:** [April 30, 2019, 12:29am UTC](https://forum.ionicframework.com/t/how-to-change-ion-toolbar-background-dynamically-ionic-v4/162745/2 "2019-04-30T00:29:03Z")

</div>

Have you tried

```auto
<ion-toolbar [ngStyle]="{ '--background': custom color }"></ion-toolbar>
```

---

<div class="post-metadata">

**Author:** ![mathm3](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mathm3/32/125615_2.png) [@mathm3](https://forum.ionicframework.com/u/mathm3)\
**Post date:** [April 30, 2019, 10:58am UTC](https://forum.ionicframework.com/t/how-to-change-ion-toolbar-background-dynamically-ionic-v4/162745/3 "2019-04-30T10:58:15Z")

</div>

> [@jjdev](#):
>
> [ngStyle]=“{ ‘–background’: custom color }”

Yes, but not working too ☹  
I really need to change the color dynamically, without it being previously in the variables.

---

<div class="post-metadata">

**Author:** ![vivek-23](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/vivek-23/32/125332_2.png) [@vivek-23](https://forum.ionicframework.com/u/vivek-23)\
**Post date:** [April 30, 2019, 11:17am UTC](https://forum.ionicframework.com/t/how-to-change-ion-toolbar-background-dynamically-ionic-v4/162745/4 "2019-04-30T11:17:42Z")

</div>

The edit doesn’t make sense to me. Are you sure you will have to add `class="ion-color"` ?

Try `[ngStyle]="{'background-color': customColor}"` and see if this works.

---

<div class="post-metadata">

**Author:** ![mathm3](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mathm3/32/125615_2.png) [@mathm3](https://forum.ionicframework.com/u/mathm3)\
**Post date:** [April 30, 2019, 11:21am UTC](https://forum.ionicframework.com/t/how-to-change-ion-toolbar-background-dynamically-ionic-v4/162745/5 "2019-04-30T11:21:04Z")

</div>

Yes, the [ngStyle]="{‘background-color’: customColor}" not work, see result:  
 ![25](https://global.discourse-cdn.com/ionicframework/original/3X/4/a/4ae3a9a8ad59af2947cd74b9a627305de6ad7949.png)

When I added the class “ion-color” with [style.background-color] it works fine. See result:  
 ![05](https://global.discourse-cdn.com/ionicframework/original/3X/3/6/36c6eaffdbdf4fd4297035522abce74e9d4ae31b.png)

* * *

**I found the solution!!**  
Add the class “ion-color” and use [style.background-color] with your color variable.

```auto
<ion-toolbar class="ion-color" [style.background-color]="customColor"></ion-toolbar>

```

---

<div class="post-metadata">

**Author:** ![vivek-23](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/vivek-23/32/125332_2.png) [@vivek-23](https://forum.ionicframework.com/u/vivek-23)\
**Post date:** [April 30, 2019, 1:20pm UTC](https://forum.ionicframework.com/t/how-to-change-ion-toolbar-background-dynamically-ionic-v4/162745/6 "2019-04-30T13:20:37Z")

</div>

Weird, because neither worked in my case in my project. I added the following code in my scss file for a page and then it worked. Of course, the color is static.

```auto
.toolbar-background{
	background-color:red;
}

```

---

<div class="post-metadata">

**Author:** ![mathm3](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mathm3/32/125615_2.png) [@mathm3](https://forum.ionicframework.com/u/mathm3)\
**Post date:** [April 30, 2019, 1:53pm UTC](https://forum.ionicframework.com/t/how-to-change-ion-toolbar-background-dynamically-ionic-v4/162745/7 "2019-04-30T13:53:48Z")

</div>

Yes of course. So it works, my problem is that I needed it to be a dynamic color.

The way I quoted worked smoothly with me. I can not explain why it worked that way, I also do not think it makes sense, but it works.
