If you're using styled-components version 3.4.10, then you have to use injectGlobal instead of createGlobalStyle, because createGlobalStyle was only release in v4 of styled-components. Check it out: [Deprecated] injectGlobal

So, in order for your code to work, you have to change a few things:

import { injectGlobal } from 'styled-components';

const GlobalStyle = injectGlobal`
html {
    height: 100%
}
* {
    padding: 0;
    margin: 0
}
`

export default GlobalStyle

And in your index.ts

import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'
import GlobalStyle from './theme/globalStyles'

ReactDOM.render(
  <React.StrictMode>
    <GlobalStyle /> // this comes first
    <App />
  </React.StrictMode>,
  document.getElementById('root')
)
Answer from mindmaster on Stack Overflow
🌐
styled-components
styled-components.com › docs › api
styled-components
Place it at the top of your React tree and the global styles will be injected when the component is "rendered". import { createGlobalStyle } from 'styled-components' const GlobalStyle = createGlobalStyle<{ $whiteColor?: boolean; }>` body { color: ${props => (props.$whiteColor ?
🌐
Scalablecss
scalablecss.com › styled-components-global-styles
How to Create Global Styles with Styled Components - Scalable CSS
June 2, 2020 - Now we need to use that file to apply the global styles to the application. Find your component which is at the top of your React tree. In many react applications, that’s typically the App.js file. Here, import your GlobalStyle component and place it inside the the top of your React tree:
🌐
Stack Overflow
stackoverflow.com › questions › 69027693 › alternative-to-createglobalstyle-from-styled-components-that-can-also-be-importa
reactjs - Alternative to createGlobalStyle from styled-components that can also be importable - Stack Overflow
This seems like it would be a good fit for your situation, as it would be relatively easy to transition from the existing structure using createGlobalStyle to one that uses this. ... import { injectGlobal } from 'styled-components'; injectGlobal` @font-face { font-family: 'Name'; font-style: normal; font-weight: 400; font-display: swap; src: url(https://fonts.gstatic.com/s/name/v12/iJWZBXyIfDnIV5PNhY1KTN7Z-Yh-B4iFU0U1Z4Y.woff2) format('woff2'); } // more fonts..
🌐
GitHub
github.com › styled-components › styled-components › issues › 2670
v5 createGlobalStyles does not work on production with 2 global styles · Issue #2670 · styled-components/styled-components
July 5, 2019 - import { createGlobalStyle } from 'styled-components/macro'; const GlobalStyling = createGlobalStyle` html { height: 100%; } :global(#root) { min-height: 100%; margin: 0; padding: 0; display: flex; flex-direction: column; flex: 1; } body { ...
Author   chriserickson
🌐
GitHub
github.com › styled-components › styled-components › issues › 3038
@import url(...) inside of createGlobalStyle causes styles other than global disappear in built version · Issue #3038 · styled-components/styled-components
February 27, 2020 - createGlobalStyle` @import url('https://fonts.googleapis.com/css?family=Ubuntu&display=swap&subset=latin-ext'); `
Author   arkadiuszbachorski
🌐
DEV Community
dev.to › mochafreddo › improving-css-loading-in-react-applications-avoiding-import-in-createglobalstyle-4d9p
Improving CSS Loading in React Applications: Avoiding `@import` in `createGlobalStyle` - DEV Community
June 17, 2024 - import { createGlobalStyle } from 'styled-components'; const GlobalStyle = createGlobalStyle` html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video { margin: 0; pa
🌐
Dilshankelsen
dilshankelsen.com › create-global-styles-with-styled-components
How To Create Global Styles With Styled Components | Dilshan Kelsen
June 24, 2021 - createGlobalStyle is a web-only API, i.e. it won't work in React Native. Create a file that contains your global styles, e.g. global.css.js. JSXCopy · import { createGlobalStyle } from 'styled-components' export default createGlobalStyle` body { margin: 0; padding: 0; color: ${props => ...
Find elsewhere
🌐
egghead.io
egghead.io › lessons › javascript-creating-global-styles-with-styled-components
Creating Global Styles with Styled Components | egghead.io
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. We wrap our application in inside of a fragment, <>, and put our new global style up at the top, ...
🌐
Storybook
storybook.js.org › recipes › styled-components
Styled Components | Storybook recipes
// .storybook/preview.jsx import { createGlobalStyle, ThemeProvider } from 'styled-components'; import { withThemeFromJSXProvider } from '@storybook/addon-themes'; import { lightTheme, darkTheme } from '../src/themes'; /* snipped for brevity */ export const decorators = [ withThemeFromJSXProvider({ themes: { light: lightTheme, dark: darkTheme, } defaultTheme: 'light', Provider: ThemeProvider, GlobalStyles, })];
🌐
Js
goober.js.org › api › createGlobalStyles
createGlobalStyles | goober
To define your global styles you need to create a GlobalStyles component and use it as part of your tree. The createGlobalStyles is available at goober/global addon. import { createGlobalStyles } from 'goober/global';
🌐
GitHub
github.com › styled-components › styled-components › blob › main › packages › styled-components › src › constructors › createGlobalStyle.ts
styled-components/packages/styled-components/src/constructors/createGlobalStyle.ts at main · styled-components/styled-components
import css from './css'; · declare const __SERVER__: boolean; · export default function createGlobalStyle<Props extends object>( strings: Styles<Props>, ...interpolations: Array<Interpolation<Props>> ) { const rules = css<Props>(strings, ...
Author   styled-components
🌐
Xstyled
xstyled.dev › docs › adding-base-styles
Adding base styles - xstyled
import { createGlobalStyle } from '@xstyled/...' const GlobalStyle = createGlobalStyle` body { color: #333; } ` function App() { return ( <> <GlobalStyle /> {/* ...
🌐
Medium
medium.com › @aimanwaseem.aw26 › styled-components-in-react-a-powerful-styling-solution-9d63f36f49c5
Styled-Components in React: A Powerful Styling Solution | by Aimanwaseem | Medium
June 14, 2023 - Here's an example: import styled, { createGlobalStyle } from 'styled-components'; const GlobalStyle = createGlobalStyle` body { font-family: 'Arial', sans-serif; background-color: #F0F0F0; } `; // Usage <React.Fragment> <GlobalStyle /> <App ...
🌐
GitHub
gist.github.com › chrislopresto › 490ef5692621177ac71c424543702bbb
styled-components v4 + createGlobalStyle + TypeScript · GitHub
import * as styledComponents from 'styled-components/native'; import {ReactNativeThemedStyledComponentsModule} from 'styled-components/native'; import {Theme} from '../themes'; const { default: styled, css, ThemeProvider, } = styledComponents as ReactNativeThemedStyledComponentsModule<Theme>; export {css, ThemeProvider}; export default styled;
🌐
GitHub
github.com › styled-components › styled-components › issues › 2526
Document or clearer support for use of @import in createGlobalStyle · Issue #2526 · styled-components/styled-components
May 2, 2019 - The styles created with createGlobalStyle are visible by hoisting imports to top-level OR the css specification is followed in this case and an error is shown to advise the user @import will not be supported within css element selectors when using createGlobalStyle.
Author   sidhuko
🌐
GitHub
github.com › styled-components › styled-components › issues › 2406
can i use `createGlobalStyle` in every component. · Issue #2406 · styled-components/styled-components
February 21, 2019 - createGlobalStyle import { createGlobalStyle } from 'styled-components'; const global = createGlobalStyle span { color: red }; export { global };
🌐
Docureacten
docureacten.github.io › managing global styles and themes
Managing Global Styles and Themes | React.js: Learn Easily with Examples
import { createGlobalStyle } from 'styled-components'; const GlobalStyle = createGlobalStyle` body { margin: 0; font-family: Arial, sans-serif; background-color: ${(props) => props.theme.backgroundColor}; } h1, h2, h3 { color: ${(props) => ...