# Accessing CSS Variables in Python Scripts

**URL:** <https://forum.inductiveautomation.com/t/accessing-css-variables-in-python-scripts/97956>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [October 30, 2024, 2:36pm UTC](https://forum.inductiveautomation.com/t/accessing-css-variables-in-python-scripts/97956 "2024-10-30T14:36:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam\_Russem](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sam_russem/32/69147_2.png) [@Sam\_Russem](https://forum.inductiveautomation.com/u/Sam_Russem)\
**Post date:** [October 30, 2024, 2:36pm UTC](https://forum.inductiveautomation.com/t/accessing-css-variables-in-python-scripts/97956/1 "2024-10-30T14:36:42Z")

</div>

Hello! (Long time listener, first time caller)

I have some custom CSS colors stored as variables in my theme file. For example, "--neutral-10: #e6e6e6;"

I know that I can leverage this color in a Perspective component by setting the color to "--neutral-10" or (sometimes) "var(--neutral-10)." For example, I can set the text color of a label by setting the its "textStyle.color" to "--neutral-10"

But is there a way that I can access the HEX value of a CSS Variable in a Python script? Say I have a script to find a good contrasting-color to a hex value, and that script works if I pass it "#e6e6e6" directly, but is there a way I can pass it "--neutral-10" and have my script find the proper HEX value?

Thank you!

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [October 30, 2024, 3:06pm UTC](https://forum.inductiveautomation.com/t/accessing-css-variables-in-python-scripts/97956/2 "2024-10-30T15:06:00Z")

</div>

Notice that a CSS variable like `--neutral-10` does not have a single hex color assigned to it, you would need to know which theme as well.

I'm not aware of a way to look it up in scripting.  
[Add transparency to built in theme color - Ignition - Inductive Automation Forum](https://forum.inductiveautomation.com/t/add-transparency-to-built-in-theme-color/65594/3)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 30, 2024, 3:16pm UTC](https://forum.inductiveautomation.com/t/accessing-css-variables-in-python-scripts/97956/3 "2024-10-30T15:16:58Z")

</div>

No, you can't.  
Or, to be accurate, you could go and read the actual .css file with a script, parse it, and pull the variable you want out of it.  
But that sounds like a terrible idea.

It seems like you're trying to find a way to transform colors dynamically.  
If that's the case, I'd suggest reading up on the [`color()`](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/color) function.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 30, 2024, 3:17pm UTC](https://forum.inductiveautomation.com/t/accessing-css-variables-in-python-scripts/97956/4 "2024-10-30T15:17:03Z")

</div>

CSS variables are basically automatically replaced strings when the CSS file is interpreted at runtime, and only 'exist' in a meaningful sense inside the frontend session. Your Python script(s) are only running on the backend, on the gateway. You'd need some kind of Javascript bridge to read values, and we don't provide one for you, nor are we likely to anytime soon.

---

<div class="post-metadata">

**Author:** ![Sam\_Russem](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sam_russem/32/69147_2.png) [@Sam\_Russem](https://forum.inductiveautomation.com/u/Sam_Russem)\
**Post date:** [October 30, 2024, 3:35pm UTC](https://forum.inductiveautomation.com/t/accessing-css-variables-in-python-scripts/97956/5 "2024-10-30T15:35:34Z")

</div>

Makes sense to me. Thanks all!
