
What are the advantages of using CSS files to style React.js Apps?
How to use CSS files in ReactJS: Different Approaches

Inline Styles
const styles = {
backgroundColor: ‘blue’,
color: ‘white’,
fontSize: ’16px’,
};
function MyComponent() {
return
;
}
External Stylesheets
The external stylesheet approach is a preferred choice of many for styling React apps using CSS. Here, the CSS code is not written inside HTML as in Inline CSS. Instead, the CSS portion is separated into an independent file. Thereafter, you need to import this file into the React component. Unlike the Inline CSS approach, the external stylesheet method provides you the entire control over CSS properties such as pseudo-selectors.
import React from 'react';
import ‘./css/styles.css’; // Path to your CSS file
function App() {
// Component code
}
export default App;
import React from 'react';
import ‘./css/styles.css’;
function App() {
return (
Hello, React!
This is a CSS-styled paragraph.
);
}
export default App;
.container {
max-width: 800px;
margin: 0 auto;
}
.title {
font-size: 24px;
color: #333;
}
.description {
font-size: 16px;
color: #777;
}
CSS Modules
// MyComponent.js
import styles from ‘./MyComponent.module.css’;
function MyComponent() {
return
;
}
/* MyComponent.module.css */
.container {
background-color: blue;
color: white;
font-size: 16px;
}
CSS-in-JS Libraries
import styled from 'styled-components';
const Container = styled.div`
background-color: blue;
color: white;
font-size: 16px;
`;
function MyComponent() {
return Hello, World!;
}
CSS Frameworks
npm install bootstrap
import 'bootstrap/dist/css/bootstrap.css';
import React from 'react';
import { Button } from ‘react-bootstrap’;
function MyComponent() {
return (
);
}
Styled Components
npm install styled-components
import React from 'react';
import styled from ‘styled-components’;
Const StyledDiv = styled.div
/* CSS styles go here */
;
const StyledDiv = styled.div`
color: #333;
background-color: #f5f5f5
padding: 10px;
function MyComponent() {
return (
This is a styled div.
);
}
const StyledButton = styled.button`
color: ${props => props.primary ? ‘white’ : ‘black’};
background-color: ${props => props.primary ? ‘blue’ : ‘gray’};
padding: 10px;
`;
CSS preprocessors
Are You Interested in Building a Top-Class Website or Mobile App?