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:

react 19.2 what is new and what to expect

React 19.2 is here: Activity API, useEffectEvent and more

Discover what’s new in React 19.2, which features long-awaited features like the Activity API and the useEffectEvent Hook.

David Omotayo
Oct 13, 2025 ⋅ 7 min read
ai dev tool power rankings

AI dev tool power rankings & comparison [Oct 2025]

Compare the top AI development tools and models of October September 2025. View updated rankings, feature breakdowns, and find the best fit for you.

Chizaram Ken
Oct 13, 2025 ⋅ 9 min read

Hooks vs. Signals: The great reactivity convergence explained

React Hooks and SolidJS Signals solve reactivity differently. Learn how each manages state and updates, and when to choose one approach over the other.

Isaac Okoro
Oct 10, 2025 ⋅ 4 min read

Exploring the new Chakra UI MCP Server

Discover how the Chakra UI MCP server integrates AI into your editor, reducing context switching and accelerating development by fetching real-time documentation, component data, and code insights directly in-app.

Emmanuel John
Oct 9, 2025 ⋅ 6 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