HTTP/2 200
date: Fri, 25 Jul 2025 23:02:43 GMT
content-type: text/html; charset=utf-8
cache-provider: CLOUDWAYS-CACHE-DE
x-frame-options: SAMEORIGIN
referrer-policy: strict-origin-when-cross-origin
strict-transport-security: max-age=31536000
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
vary: Accept-Encoding
last-modified: Fri, 25 Jul 2025 15:23:40 GMT
cache-control: max-age=0, s-maxage=2592000
expires: Fri, 25 Jul 2025 22:57:52 GMT
age: 290
x-cache: HIT
cf-cache-status: DYNAMIC
set-cookie: __cf_bm=cfzNuU1TE9BldM7Y2cCiU6Bx3udJr2K_pfV71bdZr8w-1753484563-1.0.1.1-F8EGmAN36S.wuI9mi420bMTT_SLOe1X7BSr_bIIUNXLJh.bjTp2_TtH55dvcNonnyq.VXV6k6B6JO7d6YWn33f.8xgB2_IAd8wICajHWwiE; path=/; expires=Fri, 25-Jul-25 23:32:43 GMT; domain=.css-tricks.com; HttpOnly; Secure; SameSite=None
server: cloudflare
cf-ray: 964f4951c9653585-BLR
content-encoding: gzip
Advantages to Native CSS Variables | CSS-Tricks
I tend to think variables are best left to a preprocessing step, but there are some distinct things that having them directly in CSS can do:
Daniel Imms:
[they] can change at runtime, allowing the implementation of things like theming to be done more elegantly.
i.e. change the value of a variable on a live, rendered web page and see the changes reflected everywhere that uses that variable.
Peter Gasston:
you can set the value through the setProperty()
method on the style object
Which makes #1 possible and opens up cool possibilities.
They can be scoped to an element. So perhaps you could set variables representing color to theme a site, but override them at a component level to apply different themes in smaller places as needed.
Direct Link →