I eventually figured this out, so here's how you can do it, at least if using React.

You need to define the variables in one file and export them.

// Variables.js

export const FONTSIZE_5 = '20px';

Then you need to import those variables into each component file.

// Button.js

import * as palette from './Variables.js';

Then you can use the variables in your styled-components like this:

const Button = styled.button`
  font-size: ${palette.FONTSIZE_5};
`;
Answer from colmtuite on Stack Overflow
๐ŸŒ
styled-components
styled-components.com โ€บ docs โ€บ advanced
styled-components
In the above example the styled component class takes precedence over the global class, since styled-components injects its styles during runtime at the end of the <head> by default. Thus its styles win over other single classname selectors. One solution is to bump up the specificity of the selectors in your stylesheet: /* my-component.css */ .red-bg.red-bg { background-color: red; }
Discussions

Using CSS variable with styled-components - Stack Overflow
Clearly defining variables on the ... want global variables, but more local, per page/area/component, so you need to structure you code taking that into account. The real power of CSS variables is in their inheritance (unlike SCSS variables which are injected/replaces during the build-process). The power of styled-components ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
reactjs - Migrating to Styled-Components with global SASS variables in React - Stack Overflow
Pardon me if this is an old question but I thought I chip in on how I use CSS variables for both my .scss and styled-components when the need arises. More on stackoverflow.com
๐ŸŒ stackoverflow.com
reactjs - How to use external css variables in styled-components? - Stack Overflow
I have CSS variables in separate file and I want to use them inside styled-components. It is not working as expected. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Styled Components: Global Colors Style Sheet
I'm using styled components in my app. I wanna make a global style sheet to hold all my color variables. More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Reddit
reddit.com โ€บ r/reactjs โ€บ styled components, possible to define global variables?
Styled components, possible to define global variables? : r/reactjs
August 2, 2020 - I would use a separate file for the components which are used more than once and export them. Then I can use them by importing wherever I want. ... Css is global by default, style components is scoping it down to component level.
๐ŸŒ
Josh W. Comeau
joshwcomeau.com โ€บ css โ€บ css-variables-for-react-devs
How to use CSS variables with React โ€ข Josh W. Comeau
April 13, 2020 - Now, we could solve this in a number of ways, using a styled-component mixin or a CSS class. But I think the best way to solve this problem is with CSS variables. Instead of imperatively specifying how each component should respond at different breakpoints, what if we passed it a reactive variable that tracked that for us? ... const GlobalStyles = createGlobalStyle` html { --min-tap-target-height: 32px; @media (pointer: coarse) { --min-tap-target-height: 48px; } } `;
๐ŸŒ
styled-components
styled-components.com โ€บ docs โ€บ basics
Styled Components Basic
&& a double ampersand alone has a special behavior called a "precedence boost"; this can be useful if you are dealing with a mixed styled-components and vanilla CSS environment where there might be conflicting styles: const Thing = styled.div` && { color: blue; } ` const GlobalStyle = createGlobalStyle` div${Thing} { color: red; } ` render( <React.Fragment> <GlobalStyle /> <Thing> I'm blue, da ba dee da ba daa </Thing> </React.Fragment> )
๐ŸŒ
GitHub
gist.github.com โ€บ mfix22 โ€บ f2e9f4f08c683cc6520f51342b18bf49
CSS variables in `styled-components` ยท GitHub
CSS variables in `styled-components` Raw ยท global-styles.js ยท This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
๐ŸŒ
Scalablecss
scalablecss.com โ€บ styled-components-global-styles
How to Create Global Styles with Styled Components - Scalable CSS
June 2, 2020 - Here, weโ€™ll use the createGlobalStyle function from styled-components and add some global styles: ... Inside the GlobalStyle variable is where you define all your global styles.
Find elsewhere
๐ŸŒ
daily.dev
daily.dev โ€บ home โ€บ blog โ€บ webdev โ€บ theming styled-components with css custom properties
Theming styled-components with CSS custom properties
May 6, 2021 - On one side, we have CSS custom properties, that gives you all the CSS features out-of-the-box. Variables are automatically passed downstream to children elements, you can override them with more specific rules and change them dynamically just ...
๐ŸŒ
Medium
jidefr.medium.com โ€บ using-css-variables-with-styled-components-3886f8ee35a0
Using CSS variables with styled components - Julien De Luca - Medium
June 8, 2021 - Using CSS variables with styled components Edit: I published react-css-variables, which makes defining CSS variables easy using a React component. CSS variables are a game changer, they allow easy โ€ฆ
๐ŸŒ
DEV Community
dev.to โ€บ arnonate โ€บ using-css-variables-to-tame-styled-component-props-2f9o
Using CSS Variables to Tame Styled Component Props - DEV Community
September 4, 2020 - A better approach would be to use style attribute to do the variables change: dev.to/terrierscript/tips-css-vari... ... Every time you are using props in Styled-Components you are creating another a complete clone of all the defined styles plus the change.
๐ŸŒ
GitHub
github.com โ€บ orgs โ€บ styled-components โ€บ discussions โ€บ 4216
Possible to lift local custom properties to global :root? ยท styled-components ยท Discussion #4216
Uses useEffect to iterate through the stored variables and applies them to the document.documentElement (representing the :root element), ensuring variables are extracted to the global scope. ... Import the useGlobalCssVars hook. Call the addCssVar function to define a CSS property with its corresponding value. This property will be automatically promoted to the global :root. Use the custom CSS properties in your styled components or anywhere else within your application.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 70447568 โ€บ how-to-use-external-css-variables-in-styled-components
reactjs - How to use external css variables in styled-components? - Stack Overflow
I have CSS variables in separate file and I want to use them inside styled-components. It is not working as expected. Any suggestions ? ./vars.css :root { --yellow-fs: yellow; } ./Button.style...
๐ŸŒ
egghead.io
egghead.io โ€บ lessons โ€บ javascript-creating-global-styles-with-styled-components
Creating Global Styles with Styled Components | egghead.io
We will create global styles that apply to the whole document using the styled-components library. We create a global style using the createGlobalStyle keyword and set that to a variable. Inside of that variable, we can now set our custom styles.
๐ŸŒ
CodeSandbox
codesandbox.io โ€บ s โ€บ css-variables-with-styled-components-1q887
CSS Variables with Styled Components - CodeSandbox
January 29, 2020 - CSS Variables with Styled Components by whoisryosuke using react, react-dom, react-scripts, styled-components
Published ย  Jan 10, 2020
Author ย  whoisryosuke
๐ŸŒ
Bradgarropy
bradgarropy.com โ€บ blog โ€บ from-styled-components-to-css-variables
๐Ÿ’…๐Ÿผ from styled components to css variables
April 16, 2021 - Let me tell you about the time I converted my website from a styled-components theme to css variables on a whim. The first thing I had to do was convert the theme object into custom properties. I placed the variables in the :root so that they're accessible throughout my site. const GlobalStyles = createGlobalStyle` :root { /* colors */ --black: #000000; --darkGrey: #aaaaaa; --grey: #dddddd; --white: #ffffff; --purple: #c792ea; /* palette */ --primary: var(--purple); } `
๐ŸŒ
Medium
medium.com โ€บ fbdevclagos โ€บ how-to-leverage-styled-components-and-css-variables-to-build-truly-reusable-components-in-react-4bbf50467666
How to leverage styled components and css variables to build truly reusable components in React | by Innocent Amadi | Facebook Developer Circles Lagos | Medium
April 19, 2018 - Styled-components take care of making sure your class names are unique by creating a hash out of the style rules themselves. You never have to worry about what class names your component ends up having. We retain the succinctness of writing css. Writing backgroundColor with react stylesheet never felt natural anyways ๐Ÿ™‚ ยท We retain the ability to use CSS variables.
๐ŸŒ
Sarasoueidan
sarasoueidan.com โ€บ blog โ€บ style-settings-with-css-variables
Global and Component Style Settings with CSS Variables
I used the style guide as a starting point in my CSS, as I created and defined the global project styles by deriving their values from their visual equivalents in the style guide. Just like the style guide contains settings for visual styles like colors, box shadow styles, font styles, type scales, etc., the _settings stylesheet contains variables that serve as the code equivalent of those settings, and that are used across the CSS to maintain visual consistency across the project.