# Theme awareness for UXP - CSS and different states

**URL:** <https://forums.creativeclouddeveloper.com/t/theme-awareness-for-uxp-css-and-different-states/3996>\
**Category:** UXP Plugin API\
**Tags:** css\
**Created:** [December 7, 2021, 12:28pm UTC](https://forums.creativeclouddeveloper.com/t/theme-awareness-for-uxp-css-and-different-states/3996 "2021-12-07T12:28:40Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adam](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/adam/32/1808_2.png) [@Adam](https://forums.creativeclouddeveloper.com/u/Adam)\
**Post date:** [December 7, 2021, 12:28pm UTC](https://forums.creativeclouddeveloper.com/t/theme-awareness-for-uxp-css-and-different-states/3996/1 "2021-12-07T12:28:40Z")

</div>

Hi,

I’ve found interesting options that can be used in CSS and will let custom html elements be theme aware.

for example:

```auto
    .divicon:hover{
      background-color: var(-uxp-host-widget-hover-background-color);
    }

```

There are options for regular and hover state but not for active.

Do you know if they exist?

This is the reference:

[https://www.adobe.io/photoshop/uxp/guides/theme-awareness/](https://www.adobe.io/photoshop/uxp/guides/theme-awareness/)

> Luckily, Photoshop exposes a number of theme-specific CSS variables that are perfect for making your plugin respond to the user’s theme color choice. These variables are:
> 
> - –uxp-host-background-color
> - –uxp-host-text-color
> - –uxp-host-border-color
> - –uxp-host-link-text-color
> - –uxp-host-widget-hover-background-color
> - –uxp-host-widget-hover-text-color
> - –uxp-host-widget-hover-border-color
> 
> And a few more:
> 
> - –uxp-host-text-color-secondary
> - –uxp-host-link-hover-text-color
> - –uxp-host-label-text-color
> 
> Finally, there are three dealing with font size:
> 
> - –uxp-host-font-size
> - –uxp-host-font-size-smaller
> - –uxp-host-font-size-larger

---

<div class="post-metadata">

**Author:** ![IanBarber](https://avatars.discourse-cdn.com/v4/letter/i/94ad74/32.png) [@IanBarber](https://forums.creativeclouddeveloper.com/u/IanBarber)\
**Post date:** [December 7, 2021, 5:22pm UTC](https://forums.creativeclouddeveloper.com/t/theme-awareness-for-uxp-css-and-different-states/3996/2 "2021-12-07T17:22:21Z")

</div>

I was also looking to change the Background Color of an SP-Action-Button when it’s active but had no success so I came to the conclusion its not available

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [December 8, 2021, 8:17am UTC](https://forums.creativeclouddeveloper.com/t/theme-awareness-for-uxp-css-and-different-states/3996/3 "2021-12-08T08:17:29Z")

</div>

> [@IanBarber](#):
>
> was also looking to change the Background Color of an SP-Action-Button when it’s active but had no success

This works just fine for me

```scss
        .btn-color-#{$color} {
          background-color: $rgbColor;

          &:hover {
            background-color: $btnHoverColor;
          }

          &:active {
            background-color: $btnActiveColor;
          }
        }

```

---

<div class="post-metadata">

**Author:** ![Adam](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/adam/32/1808_2.png) [@Adam](https://forums.creativeclouddeveloper.com/u/Adam)\
**Post date:** [December 9, 2021, 6:48pm UTC](https://forums.creativeclouddeveloper.com/t/theme-awareness-for-uxp-css-and-different-states/3996/4 "2021-12-09T18:48:52Z")

</div>

Hi, I’m getting errors when I’m using this code:

 ![Zrzut ekranu 2021-12-9 o 19.47.34](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/1/1a6e8b4ebd8cb79ae6d7c25ca9703ff2aa5b9b41.png)

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [December 9, 2021, 10:39pm UTC](https://forums.creativeclouddeveloper.com/t/theme-awareness-for-uxp-css-and-different-states/3996/5 "2021-12-09T22:39:31Z")

</div>

Well… It’s a copy-paste from my SCSS with some variables. You should use it like:

```auto
.btn-color-blue {
  background-color: blue;
}

.btn-color-blue:hover {
  background-color: cyan;
}

.btn-color-blue:active {
  background-color: magenta;
}

```

---

<div class="post-metadata">

**Author:** ![Adam](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/adam/32/1808_2.png) [@Adam](https://forums.creativeclouddeveloper.com/u/Adam)\
**Post date:** [February 9, 2022, 1:36pm UTC](https://forums.creativeclouddeveloper.com/t/theme-awareness-for-uxp-css-and-different-states/3996/6 "2022-02-09T13:36:58Z")

</div>

Is it possible to change the element in html (like logo.png) based on theme?

---

<div class="post-metadata">

**Author:** ![simonhenke](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/simonhenke/32/957_2.png) [@simonhenke](https://forums.creativeclouddeveloper.com/u/simonhenke)\
**Post date:** [February 9, 2022, 5:22pm UTC](https://forums.creativeclouddeveloper.com/t/theme-awareness-for-uxp-css-and-different-states/3996/7 "2022-02-09T17:22:26Z")

</div>

Yes: The application has a property called `kuiBrightnessLevel` indicating the current theme. It can have the following values:` 'kPanelBrightnessDarkGray' | 'kPanelBrightnessMediumGray' | 'kPanelBrightnessLightGray' | 'kPanelBrightnessOriginal'`

In order to stay up-to-date, you can set up and event listener for the `set` event and then check if it matches a specific pattern to see if this specific settings was changed. This is how the set event descriptor would look like:

```auto
{
   "_obj": "set",
   "_target": [
      {
         "_ref": "property",
         "_property": "interfacePrefs"
      },
      {
         "_ref": "application",
         "_enum": "ordinal",
         "_value": "targetEnum"
      }
   ],
   "to": {
      "_obj": "interfacePrefs",
      "kuiBrightnessLevel": {
         "_enum": "uiBrightnessLevelEnumType",
         "_value": "kPanelBrightnessDarkGray"
      }
   }
}

```

so the handler could look like

```auto
const onSetEvent = (event, descriptor) => {
  if (descriptor.to && descriptor.to.kuiBrightnessLevel) {
    const activeTheme = descriptor.to.kuiBrightnessLevel._value
  }
};

```

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [February 9, 2022, 6:16pm UTC](https://forums.creativeclouddeveloper.com/t/theme-awareness-for-uxp-css-and-different-states/3996/8 "2022-02-09T18:16:07Z")

</div>

Suggestion 🙂

```auto
if (descriptor.to?.kuiBrightnessLevel) {

```

---

<div class="post-metadata">

**Author:** ![Adam](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/adam/32/1808_2.png) [@Adam](https://forums.creativeclouddeveloper.com/u/Adam)\
**Post date:** [February 10, 2022, 10:21am UTC](https://forums.creativeclouddeveloper.com/t/theme-awareness-for-uxp-css-and-different-states/3996/9 "2022-02-10T10:21:00Z")

</div>

Thank you very much Simon,

I’ve found a way to do it in CSS:

```auto
  @media (prefers-color-scheme: dark), (prefers-color-scheme: darkest) {
    .logo{background: url('./img/logo2502.png') no-repeat;}

  }

  
@media (prefers-color-scheme: light), (prefers-color-scheme: lightest)
 {
.logo{background: url('./img/logo2502dark.png') no-repeat;}
 }

.logo {
    text-align: center;
    margin-bottom: 12px;
    margin-top: 12px;
    width: 250px;
    height: 35px;
}   

```

---

<div class="post-metadata">

**Author:** ![simonhenke](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/simonhenke/32/957_2.png) [@simonhenke](https://forums.creativeclouddeveloper.com/u/simonhenke)\
**Post date:** [February 10, 2022, 11:39am UTC](https://forums.creativeclouddeveloper.com/t/theme-awareness-for-uxp-css-and-different-states/3996/10 "2022-02-10T11:39:51Z")

</div>

Yes that works, too. I though you were explicitly looking for a solution to change HTML, but if you only need to switch the image, the CSS background / background-image property also works fine.
