2025-03-20
5201
#css
Idorenyin Obong
14833
Mar 20, 2025 â‹… 18 min read

How to use CSS variables like a pro

Idorenyin Obong Software engineer with a flair for writing.

Recent posts:

How to manage JavaScript closures in React

Learn how to manage JavaScript closures in React and explore real-life examples of proper JavaScript closure management.

Andrew Evans
Mar 21, 2025 â‹… 10 min read
Will AI Take Developers’ Jobs?

Will AI take developers’ jobs?

Explore AI’s impact in software development, its limitations, and how developers can stay competitive in the AI-driven industry.

Frank Joseph
Mar 20, 2025 â‹… 5 min read
top ten react native chart libraries

The top 10 React Native charts libraries for 2025

Looking for the best React Native chart library? Explore the top 10 options, compare performance, and find the right tool for your project.

Aman Mittal
Mar 19, 2025 â‹… 7 min read
bash vs zsh

Bash vs. Zsh: Key differences and when to use each

Compare the Bash vs. Zsh shell command languages, explore their differences, and see how to use both successfully.

Wisdom Ekpotu
Mar 19, 2025 â‹… 9 min read
View all posts

3 Replies to "How to use CSS variables like a pro"

  1. I strangely couldn’t retrieve the value from documentElement via getPropertyValue, as it was not set on that element. Setting the value via javascript to black works fine, and then retrieval works and comes back as black. (I had one variable definition in css under :root in header style definitions – red, and one value set on the html element itself via chrome devtools – black)
    Instead using getComputedStyle worked okay as it supports the pseudo selector as second argument and I was able to retrieve the original css value of red, or any overloaded value as appropriate.

    window.getComputedStyle(window.document.documentElement,”:root”).getPropertyValue(‘–joy-colour’)

Leave a Reply