# Change color of local svg icons

**URL:** <https://community.openhab.org/t/change-color-of-local-svg-icons/160851>\
**Category:** UIs\
**Created:** [December 14, 2024, 12:44pm UTC](https://community.openhab.org/t/change-color-of-local-svg-icons/160851 "2024-12-14T12:44:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dirk\_Albrecht](https://community.openhab.org/user_avatar/community.openhab.org/dirk_albrecht/32/87128_2.png) [@Dirk\_Albrecht](https://community.openhab.org/u/Dirk_Albrecht)\
**Post date:** [December 14, 2024, 12:44pm UTC](https://community.openhab.org/t/change-color-of-local-svg-icons/160851/1 "2024-12-14T12:44:15Z")

</div>

I seem to have a simple problem around icon colors, which I can’t seem to solve  
I’m using iconify icons, choosing the icon and icon-color through state-dependant choices…

```auto
value: ""
config:
  icon: ={ON:'if:mdi:lamps',OFF:'if:mdi:lamps-outline'}[@'Suite1_BedsideLamps_Switch']
  iconColor: ={ON:'gold',OFF:'#bbb'}[@'Suite1_BedsideLamps_Switch']
  color: yellow

```

This works well for me.

I tried to the same thing with locally stored (`openhab-conf/icons/classic`) icons (in svg format). while the `icon` choice expression works, the `iconColor` choice doesn’t work. The iconColor would always stay black:

```auto
value: ""
config:
  icon: ={ON:'if:mdi:lamps',OFF:'ceilinglamp'}[@'Suite1_BedsideLamps_Switch']
  iconColor: ={ON:'green',OFF:'red'}[@'Suite1_BedsideLamps_Switch']
  color: yellow

```

 ![image](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/9/4/94fdf10399447437825ef6dcad0e19dbbb07dc52.png)  
 ![image](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/b/3/b38c5b6bcbeff7b4db5015cd11e0f0007520a87a.png)

I looked into the svg file, which I downloaded from iconify and stored locally:

```auto
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
    <path fill="currentColor" d="M8 9h3V4h2v5h3l4 8H4zm6 9a2 2 0 0 1-2 2a2 2 0 0 1-2-2z"/>
</svg>

```

I believe, I read somewhere that the color was set through the fill attribute set to `currentColor` …, which is the case.

So any hint on how I can get locally stored svg icon react to the change of the `iconColor` attribute?

(obviously the example given here is for illustrative purposes and doesn’t make much sense … what I’d actually like to do is to a few additional mdi-style icons for consistency, in order to extend the already very helpful mdi-iconset. And I would like the icons to react similarly as the iconify:mdi iconset stored online, without having to hardcode the iconColor in the locally stored extensions.

I have read about restrictions for openhab icons … would they apply to all “locally stored” icons … which would explain the behavior. But still that doesn’t provide a solution.

---

<div class="post-metadata">

**Author:** ![JustinG](https://community.openhab.org/user_avatar/community.openhab.org/justing/32/55948_2.png) [@JustinG](https://community.openhab.org/u/JustinG)\
**Post date:** [December 14, 2024, 4:27pm UTC](https://community.openhab.org/t/change-color-of-local-svg-icons/160851/2 "2024-12-14T16:27:03Z")

</div>

> [@Dirk\_Albrecht](#):
>
> would they apply to all “locally stored” icons

All the locally stored icons are served in the same way, whether they are the built-in iconset or custom made icons. There’s something about the icon servelet that doesn’t really work with the color settings and `customColor`. If I recall, there was some work a while back to try and get this working, but I don’t remember where that stands.

If this is in a custom widget where you have a little more control over where the icon comes from, you can try:

> [@Custom SVG Icon Sets](https://community.openhab.org/t/custom-svg-icon-sets/138504):
>
> The MainUI devs have done an amazing job making sure that when making your own custom widgets, you have access hundreds of possible icons, with the moderately recent addition of the iconify resource pushing that into the thousands. Even so, there are still times when only a custom icon will do. In these circumstances, OH gives you an ability to [add your custom icons to the system](https://www.openhab.org/docs/configuration/items.html#icons) to be called just as any of the other OH icons are. For example, my sonos speakers use a custom SVG icon that can …

Otherwise, for now your best bet would be to produce a couple of different color versions of the icons and make the icon names include the color.

---

<div class="post-metadata">

**Author:** ![xsherlock](https://community.openhab.org/user_avatar/community.openhab.org/xsherlock/32/37207_2.png) [@xsherlock](https://community.openhab.org/u/xsherlock)\
**Post date:** [February 20, 2025, 2:14pm UTC](https://community.openhab.org/t/change-color-of-local-svg-icons/160851/3 "2025-02-20T14:14:51Z")

</div>

Jizz I just lost half a day trying to get that work as forum here was down for maintenance and chat gpt insisted it can be done.

 ![image](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/0/3/034e21a4cbad1d7ff42449af7ef6032630e29c00.png)

never trust AI
