ReactCSS
ReactCSS
CSS in React is used to style the React App or Component. The style attribute is the
most used attribute for styling in React applications, which adds dynamically-computed
styles at render time. It accepts a JavaScript object in camelCased properties rather
than a CSS string. There are many ways available to add styling to your React App or
Component with CSS. Here, we are going to discuss mainly four ways to style React
Components, which are given below:
1. Inline Styling
2. CSS Stylesheet
3. CSS Module
4. Styled Components
1. Inline Styling
import React from 'react';
render() {
return (
<div>
</div>
);
render() {
return (
<div>
</div>
);
render() {
const mystyle = {
color: "Green",
backgroundColor: "lightBlue",
padding: "10px",
fontFamily: "Arial"
};
return (
<div>
</div>
);
App.css
1. body {
2. background-color: #008080;
3. color: yellow;
4. padding: 40px;
5. font-family: Arial;
6. text-align: center;
7. }
CSS Module
CSS Module is another way of adding styles to your application. It is a CSS file where all
class names and animation names are scoped locally by default. It is available only for
the component which imports it, means any styling you add can never be applied to
other components without your permission, and you never need to worry about name
conflicts. You can create CSS Module with the .module.css extension like
a myStyles.module.css name.
myStyles.module.css
1. .mystyle {
2. background-color: #cdc0b0;
3. color: Red;
4. padding: 10px;
5. font-family: Arial;
6. text-align: center;
7. }
8.
9. .parastyle{
10. color: Green;
11. font-family: Arial;
12. font-size: 35px;
13. text-align: center;
14. }
Styled Components
Styled-components is a library for React. It uses enhance CSS for styling React
component systems in your application, which is written with a mixture of JavaScript and
CSS.
Installation
The styled-components library takes a single command to install in your React
application. which is:
Example