You cannot directly import CSS or any other static files into typescript using only the typescript compiler, but you can with the help of some build tools...

For example using webpack, you can set up the css-loader and style-loader to search your source code for require('./whatever.css') and add it to the build before safely compiling your typescript. If you also have webpack generate your HTML then your CSS will be automatically injected as a stylesheet.

Answer from alechill on Stack Overflow
Discussions

reactjs - How to write CSS / SCSS / PostCSS inside React .tsx file as JavaScript String in VSCode and WebStorm? - Stack Overflow
0 How to use scss with css modules / postcss inside components · 5 SCSS files not compiling to CSS in react using Webpack More on stackoverflow.com
🌐 stackoverflow.com
css module/ importing css files in tsx or ts files
I am trying to make css-modules and typescript to work together with webpack. So i have this file import * as styles from './styles.css'; which throwing an error about not found module. Ok. After s... More on github.com
🌐 github.com
20
May 21, 2016
Is there a solution for CSS modules that would allow to have TSX and CSS in the same file?
I think Emotion CSS might have the functionality you are looking for. More on reddit.com
🌐 r/react
10
0
May 26, 2023
reactjs - Syntax Highlighting for CSS in a Style Tag in a TSX Component - Stack Overflow
In my React app, I like to write CSS style within a style tag of a given TSX component. Is there a way to achieve VS Code syntax highlighting for CSS within this context? Currently, the entire file More on stackoverflow.com
🌐 stackoverflow.com
🌐
DEV Community
dev.to › domnikl › scoped-css-for-react-components-with-typescript-31a4
Scoped CSS for React Components with TypeScript - DEV Community
May 25, 2021 - I came to React, looking for Single ... It works like this: you import the CSS as a JavaScript module , which have been mapped from your CSS class names and assign those as className properties in the JSX....
🌐
Medium
medium.com › @dimi_2011 › setting-up-css-modules-in-typescript-project-52596526d19
Setting up CSS Modules in Typescript project | by Ivan Dimitrijevic | Medium
March 21, 2023 - I used css-loader for such. So you need to install it first with the command. ... Then you need to specify in you webpack configuration file in section module -> rules how CSS files will be loaded.
🌐
Oida
oida.dev › typescript-react › styles
TypeScript and React: Styles and CSS
For the course of this section, we do it per file. The css template function takes CSS and returns an object you can pass to your components. The properties are compatible with CSS.Properties from csstype. In fact, it uses csstype under the hood.
🌐
Maxim Zhukov
fsou1.github.io › Style_react_components
How to import CSS and style TSX React components - Maxim Zhukov
July 13, 2021 - For this, in the command line we ... './App.css';. This line imports styles from the CSS file, and we can use them as class names like <header className="App-header">....
Find elsewhere
🌐
GitHub
github.com › s-panferov › awesome-typescript-loader › issues › 146
css module/ importing css files in tsx or ts files · Issue #146 · s-panferov/awesome-typescript-loader
May 21, 2016 - I am trying to make css-modules and typescript to work together with webpack. So i have this file import * as styles from './styles.css'; which throwing an error about not found module. Ok. After s...
Published   May 21, 2016
Author   Truedrog
🌐
Reddit
reddit.com › r/react › is there a solution for css modules that would allow to have tsx and css in the same file?
r/react on Reddit: Is there a solution for CSS modules that would allow to have TSX and CSS in the same file?
May 26, 2023 - ... and unless I am terrible with Google, such thing does not exist in Next.js/React ecosystem, which is unfortunate. ... _ah_, good to know. So, everyone who migrated to next.js v13 just have `.css` file for every component/route?
🌐
DhiWise
dhiwise.com › post › how-to-elevate-ui-design-using-react-cssproperties-typescript
Implementing React CSSProperties Typescript for Styling
May 20, 2024 - To keep your react components clean and focused on functionality, it's a good idea to import style definitions and constants from separate files. This not only makes your components easier to read but also promotes reusability of styles across your project. Here's how you might import a CSS module and a TypeScript constant in a component: ... 1// styles.module.css 2.container { 3 display: flex; 4 justify-content: center; 5} 6 7// constants.ts 8export const MAX_WIDTH = '1200px'; 9 10// MyComponent.tsx 11import React from 'react'; 12import styles from './styles.module.css'; 13import { MAX_WIDTH } from './constants'; 14 15const MyComponent: React.FC = () => { 16 return ( 17 <div className={styles.container} style={{ maxWidth: MAX_WIDTH }}> 18 Content goes here.
🌐
GitHub
github.com › vitejs › vite-plugin-react › issues › 107
Be able to use styleName or style tag inside jsx or tsx for scoped css · Issue #107 · vitejs/vite-plugin-react
February 13, 2023 - One has to manually import styles for every component. import styles from './App.module.css' function App() { return ( <div className={styles.a}> <h1 className={styles.b}>123</h1> </div> ) } export default App · As a developer using react and ...
Author   gabalicious
🌐
Reddit
reddit.com › r/reactjs › do you prefer keeping styling in the component file or in a dedicated style file
r/reactjs on Reddit: Do you prefer keeping styling in the component file or in a dedicated style file
March 8, 2023 -

I said "dedicated style file" instead of stylesheet since we have more than just CSS to apply styles nowadays. Emotion and MUI's sx props, Tailwind's CSS classes, styled-components styled function, and much more.

There are instances I saw that some people prefer keeping a long list of class names or sx props in the TSX file, which I'm not sure whether is a good idea in the long run since it sounds like it will affect readability, especially when conditional rendering comes into play.

While separating them also has concerns as well because now I need to have at least two files opened to have a full picture of what the component is about.

What do you think?

🌐
Hono
hono.dev › docs › helpers › css
css Helper - Hono
February 11, 2026 - tsx · const globalClass = css` ... <h1>Hello!</h1> <p>Today is a good day.</p> </div> ) Or you can write CSS in the <Style /> component with the css literal....
🌐
Next.js
nextjs.org › learn › dashboard-app › css-styling
App Router: CSS Styling | Next.js
You can use this file to add CSS rules to all the routes in your application - such as CSS reset rules, site-wide styles for HTML elements like links, and more. You can import global.css in any component in your application, but it's usually ...
🌐
Carl Rippon
carlrippon.com › using-css-react-typescript-with-webpack5
Using CSS in React and TypeScript with Webpack 5
January 27, 2021 - CSS modules solve this problem by allowing us to scope CSS to a particular component. Let’s adjust our components to reference CSS modules: ... The import statement is slightly different. We are referencing a file with a .module.css suffix and importing a variable from the file which will contain all the CSS class names.
🌐
Medium
medium.com › @sapegin › css-modules-with-typescript-and-webpack-6b221ebe5f10
How to use CSS Modules with TypeScript and webpack | by Artem Sapegin | Medium
March 27, 2019 - Using CSS Modules with TypeScript is not as obvious as with JavaScript. The reason is that TypeScript has special treatment for imports and if you try to use CSS Modules the same way you did in JavaScript:
🌐
Medium
medium.com › @msgold › styled-components-in-react-and-typescript-456843804b99
Styled Components in React and TypeScript | by Michael Gold | Medium
August 29, 2023 - Here is the code to replace in App.tsx that does just that: import React, { useState } from 'react' import logo from './logo.svg' import './App.css'const App = () => { const colors: string[] = ['red', 'brown', 'lightgreen', 'yellow', 'green', 'orange', 'purple', 'blue' ] const [areaColor, setAreaColor] = useState('white')
🌐
LogRocket
blog.logrocket.com › home › using styled-components in typescript: a tutorial with examples
Using styled-components in TypeScript: A tutorial with examples - LogRocket Blog
June 4, 2024 - It should look like this: import React from 'react'; const App:React.FC = ()=> ( <> </> ) export default App; In your src folder, create a styles folder. You can name it whatever you like; I’ll name mine styles.