How to import a CSS file in React ? Last Updated : 15 Apr, 2025 Comments Improve Suggest changes Like Article Like Report In React applications, styling is a crucial aspect of creating visually appealing and responsive user interfaces. CSS (Cascading Style Sheets) files are commonly used to define styles for React components. Importing CSS files into React components allows developers to apply styles to specific elements and create a cohesive design for their applications. This guide provides a detailed description of how to import CSS files in React components, including best practices and optional configurations such as CSS Modules. Table of Content Steps to Import a CSS file in a ReactImporting an External CSS FileUsing Inline CSS in ReactUsing Internal CSS in React Steps to Import a CSS file in a React:Step 1: Create a new ReactJS project and install the required dependencies:- npx create-react-app css-appStep 2: Navigate to the root directory of your project using the following command. cd css-appProject Structure: Importing an External CSS File:In this code i have set the background color of page to aqua, and all the data in the h1 tag will have a border radius of 20px , background color to pastel pink and text should be aligned to center with margin from top 100px. Code: Write the following code in index.css file JavaScript /* index.css */ * { margin: 0; } body { background-color: aqua; } h1 { border-radius: 20px; background-color: rgb(251, 141, 196); text-align: center; margin-top: 100px; } In index.js file write the below code: Note : Import the index.css file using import './index.css'; Importing CSS in ReactJs: JavaScript import React from 'react'; import ReactDOM from 'react-dom'; import './index.css'; ReactDOM.render( <> <h1> hello Geek!!</h1> </> , document.getElementById("root") ); Using Inline CSS in React:Note : In index.js file write this code this will apply the cs using the inline css: In this we don't need to create a seprate index.css file. We have applied css to the h1 tag withing the body part using <style>. JavaScript import React from 'react'; import ReactDOM from 'react-dom'; ReactDOM.render( <> <head> <style>// importing css {` body { margin: 0; background-color: aqua; } `} </style> </head> <body> <h1 style={{ borderRadius: '20px', backgroundColor: 'rgb(251, 141, 196)', textAlign: 'center', marginTop: '100px' }}>hello Geek!!</h1> </body> </>, document.getElementById("root") ); Using Internal CSS in React :Note : In index.js file write this code this will apply the cs using the internal css: In this code we have used the internal css where all the css is defined in the <head> tag using the <style>, below is the code snippet: JavaScript import React from 'react'; import ReactDOM from 'react-dom'; ReactDOM.render( <> <head> <style> {` * { margin: 0; } body { background-color: aqua; } h1 { border-radius: 20px; background-color: rgb(251, 141, 196); text-align: center; margin-top: 100px; } `} </style> </head> <body> <h1>hello Geek!!</h1> </body> </>, document.getElementById("root") ); Start your application using the following command. npm startOutput: Comment More infoAdvertise with us Next Article How to import a CSS file in React ? A at52kvoq Follow Improve Article Tags : Web Technologies CSS ReactJS React-Questions Similar Reads How to import regular CSS file in SCSS file ? Importing a regular CSS file into a SCSS file allows you to use standard CSS styles within your SCSS file. This is done by using the @import directive, enabling the CSS file to be included and compiled along with SCSS styles during preprocessing.@import keyword: The @import keyword in SCSS allows yo 3 min read How to Read CSV files in React.js ? CSV (Comma-Separated Values) files are a common format for storing and exchanging tabular data. When working with React.js, reading and parsing CSV files can be a useful task for handling data input. To read CSV files in React JS we have to use external libraries as there in no inbuilt methods avail 4 min read React MUI How to customize React MUI is a UI library that provides fully-loaded components, bringing our own design system to our production-ready components. MUI is a user interface library that provides predefined and customizable React components for faster and easy web development, these Material-UI components are based o 4 min read How to add code input in React JS? In this article, we are going to learn how we can add Code Input in React JS. React is a front-end JavaScript library for constructing user interfaces or UI components. It is maintained by Facebook and a community of individual developers and companies. Approach to add code input: To incorporate our 2 min read How to Include CSS Files in Vue2 ? VueJS is one of the greatest frameworks for JavaScript similar to ReactJS. The user interface layer is designed with VueJS. When working with Vue2, styling your components is an essential aspect of creating a visually appealing and user-friendly application. In Vue2 you can include CSS files in vari 4 min read How to modularize code in ReactJS ? Modularize code in React JS refers to dividing it into segments or modules, where each file is responsible for a feature or specific functionality. React code can easily be modularized by using the component structure. The approach is to define each component into different files. With each componen 3 min read How to Implement Chakra UI in ReactJS ? Chakra UI is a powerful component library for React that is designed and developed by Segun Adebayo to build front-end applications. The Chakra UI comes with simple yet easy-to-understand documentation that gives us guidelines on how to build a reusable component, thereby reducing the time spent on 3 min read How to Drawing Canvas in React.js ? In this article, we are going to learn how we can add drawing canvas in ReactJs. React is a free and open-source front-end JavaScript library for building user interfaces or UI components. It is maintained by Facebook and a community of individual developers and companies. Prerequisites:NodeJS or NP 2 min read How to use files in public folder in ReactJS ? In React, the files store public folder contains static files such as index.html, javascript library files, images, and other assets, etc. which you don't want to be processed by Webpack. Files in this folder are copied and pasted as they are directly into the build folder. Files inside the `public` 2 min read How To Create a Website in ReactJS? ReactJS is one of the most popular JavaScript libraries for building user interfaces. It allows you to create dynamic, reusable UI components and efficiently manage state and events. In this article, we'll walk through the steps to create a basic website using ReactJS.PrerequisitesNPM & Node.jsR 5 min read Like