Since these values are defined at root level, you can just update them using document. I am not exactly sure on how you can access the document in angular, but once you have document, you can do something like this:

document.documentElement.style.setProperty(`--${your-variable}`, value + suffix); //suffix may be px or ''

This way, you will directly set the css variable which will take effect at all the places and you will not have to target individual elements.

Answer from ashfaq.p on Stack Overflow
Discussions

reactjs - How to define css variables in style attribute in React and TypeScript - Stack Overflow
Not sure how another answers handle ... react/typescript project to test. 2021-01-29T21:10:04.447Z+00:00 ... @jcubic because MyCustomCSS extends from CSSProperties other properties should be assignable as well. 2021-03-04T10:09:30.097Z+00:00 ... I mean that I like the solution because I can only use custom properties I've defined in the type, so If I set --length: ... More on stackoverflow.com
🌐 stackoverflow.com
angular - How to set TypeScript variable value as CSS property? - Stack Overflow
I have an image (inside a material card) which changes every 30 seconds. I have the height of the image (as a TS variable) and I want to set it as the height of the loaded image. I tried the below More on stackoverflow.com
🌐 stackoverflow.com
Setting a CSS variable in `attrs` throws a TypeScript error
Environment System: OS: macOS 13.4 CPU: (10) arm64 Apple M1 Pro Memory: 52.38 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 18.16.0 - ~/.asdf/installs/nodejs/18.16.0/bin/node Yarn: 4.0.1 - ~/... More on github.com
🌐 github.com
1
November 8, 2023
Get CSS Parameter from Typescript Angular - Stack Overflow
Unfortunately, there is no way to access SASS variable directly from typescript/javascript code. However, we can make a workaround to access those variables. You can view the workaround in the post mentioned above ... As mentioned by @tgall019, CSS variables can be accessed in typescript. More on stackoverflow.com
🌐 stackoverflow.com
🌐
8hob
8hob.io › posts › javascript › typescript: typing css variables in react
TypeScript: Typing CSS Variables in React
June 1, 2025 - Explicitly spelling out the CSS variable names has the advantage of maximized type safety: The TypeScript compiler will catch any typos in the CSS variable name. If the CSS variable accepts a different type such as any string, we can replace "classical" | "modern" with string. If the CSS variable accepts a special CSS data type, such as color, we can use the corresponding type defined in the CSSType package, like the following: import { DataType } from "csstype"; declare module "react" { interface CSSProperties { "--component-ambient-color"?: DataType.Color; } } export default function App() { return <h1 style={{ "--component-ambient-color": "red" }}>Hello World!</h1>; }
🌐
W3Schools
w3schools.com › css › css3_variables_javascript.asp
CSS Change Variables With JavaScript
Static/Relative Position Fixed/Absolute Position Sticky Position Code Challenge CSS Position Offsets ... The var() Function Overriding Variables Variables and JavaScript Variables in MQ Code Challenge CSS @property
🌐
Intertech
intertech.com › home › using css variables in angular
Using CSS Variables In Angular - Intertech
October 26, 2023 - –hoverColor is the CSS variable · button:hover { background-color: var(--hoverColor, grey); } So in this case, the background-color will be “white” because –hoverColor is defined in the :root · If it isn’t defined, it will get the default “grey” value · Common Code · For both solutions, these things remain the same: Define the “hoverColorVar” variable in the component Typescript: export class AppComponent { // Note it is important to set this to 'null' here to get the default color in css.
🌐
GitHub
github.com › styled-components › styled-components › issues › 4209
Setting a CSS variable in `attrs` throws a TypeScript error · Issue #4209 · styled-components/styled-components
November 8, 2023 - Try to set a CSS variable in attrs's inline styles · Variable is set · Variable is recognized as a valid entry · Variable is set · TypeScript throws the following error: Argument of type '({ dim }: ExecutionContext & FastOmit<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "dim"> & { ...; }) => { ...; }' is not assignable to parameter of type 'Attrs<Substitute<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, { dim: number; }>>'. Type '({ dim }: ExecutionContext & FastOmit<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "dim"> & { ...;
Author   PatrickDeVries
Find elsewhere
🌐
Curiouslychase
curiouslychase.com › posts › fix-css-variable-keys-in-style-attributes-in-react-and-typescript
Fix CSS variable keys in style attributes in React and Typescript
February 22, 2021 - This loop has driven every major shift in my career—from launching teams at Walmart to building AI systems at Plumb.
🌐
npm
npmjs.com › package › css-variable
css-variable - npm
define CSS custom properties (variables) in JS. Latest version: 8.0.0, last published: a month ago. Start using css-variable in your project by running `npm i css-variable`. There are 1 other projects in the npm registry using css-variable.
      » npm install css-variable
    
Published   Nov 04, 2025
Version   8.0.0
Author   Jan Nicklas
🌐
HTML Goodies
htmlgoodies.com › home › css
A Guide to CSS Variable Scoping in Angular | HTMLGoodies.com
September 21, 2021 - You declare a CSS variable at the top of your CSS file, as in the first snippet below, or at the rule level, as seen in the second snippet: ... When you apply the CSSStyleDeclaration’s setProperty() method at the document level in TypeScript or JavaScript, the variable is added to the HTML ...
🌐
Webdevtutor
webdevtutor.net › blog › typescript-pass-variable-to-css
How to Pass Variables from TypeScript to CSS
One of the most effective ways to pass variables from TypeScript to CSS is by leveraging CSS custom properties, also known as CSS variables. These variables can be defined and manipulated directly in CSS, allowing you to update styles dynamically. Here's a simple example of how you can define ...
🌐
David Walsh
davidwalsh.name › css-variables-javascript
How to Get and Set CSS Variable Values with JavaScript
October 8, 2018 - I’ve been for a few days using this API and its greats. The only thing that I don’t like is that if you set the vars in a Child, and then you want to get the variables in a SubChild, you won’t be able to fetch anything. On the other hand if you use it in your css or styles property, it will work…
🌐
Bobby Hadz
bobbyhadz.com › blog › typescript-add-css-style-to-element
Set CSS styles on an Element using TypeScript | bobbyhadz
February 29, 2024 - Copied!// 👇️ const box: HTMLElement | null const box = document.getElementById('box'); if (box != null) { box.style.setProperty('background-color', 'lime'); box.style.setProperty('color', 'white'); } ... propertyName - the name of the CSS property we want to modify. Note that property names of multiple words must be hyphenated. ... I've also written an article on how to pass CSS styles as props in React TypeScript. You can also use the style object to read CSS property values from the element.
🌐
Stack Overflow
stackoverflow.com › questions › 54356596 › importing-css-variables-into-a-typescript-file
Importing CSS variables into a Typescript file
Update: if all you're trying to do it to use your globally defined css vars inside your theme.ts, you should probably be ok with just copying the variable names
🌐
Webdevtutor
webdevtutor.net › blog › typescript-set-css-variable
How to Set CSS Variables in TypeScript
In this post, we'll explore the different ways you can set and manipulate CSS variables when writing TypeScript code.
🌐
Reddit
reddit.com › r/reactjs › css variables with styled-components and typescript error
r/reactjs on Reddit: Css variables with styled-components and typescript error
July 8, 2024 -

So I've been delving more into styling and styled-components, I came across Josh Comeau's article on styled-components and liked his approach to pass a style object with css variables instead of props, however I can't get typescript to stop complaining, here's an example:

<Button style={{'--accent': 'red'}}>

And the styled component:

type Props = { style: CSSProperties }

export const Button = styled.button<Props>`
border: 2px solid var(--accent); 
border-radius: 4px; 
padding: 16px; 
margin: 8px; 
background: white; 
color: var(--accent);
`;

But I get the error "Object literal may only specify known properties...", I've done a bit of googling and found the following solution, but it feels like a pain in the ass to smear "as CSSProperties" everywhere:

<Button style={{ '--accent': 'black', } as CSSProperties}>

Is there a better way to do this?