3 Ways of Adding Styles In React Applications
A Beginner’s Guide with an example project
React is one of the popular Javascript libraries and it’s going to be more popular in 2021 and beyond. React is released first in 2013 and it gained a lot of popularity over the years. It’s a declarative, component-based, and efficient javascript library for building user interfaces.
React is a simple javascript UI library for building efficient and faster user interfaces. It’s a lightweight library which makes it popular. It follows the component design pattern, declarative programming paradigm, and functional programming concepts to make the front end apps efficient. It uses Virtual DOM to efficiently manipulates DOM. It follows one-way data flow from higher-order components to lower-order components.
In this post, we will see how many ways you can apply styles in React applications.
- Prerequisites
- Example Project
- External Stylesheet
- Inline Style
- With Objects
- Summary
- Conclusion
Prerequisites
There are some prerequisites for this article. You need to have nodejs installed on your laptop. If you want to practice and run this on your laptop you need to have these on your machine.
Example Project
This is a simple project which demonstrates developing and running a React application with NodeJS. We have a simple app in which we can add users, count, and display them at the side, and retrieve them whenever you want.

Here is a Github link to this project. You can clone it and run it on your machine.
// clone the project
git clone https://github.com/bbachi/react-nodejs-example.git// strat the api
cd api
npm install
npm run dev// start the react appcd my-app
npm install
npm startExternal Stylesheet
In this method, you can import an external stylesheet into your component use classes. But you should use className instead of class to apply styles for the React elements.
The external style can be anything here. You can have separate CSS files based on your components and features. It doesn't matter how many CSS files you have, importing CSS files into components have the same pattern. If your component needs styles from multiple CSS files you can import those in the component. For example, we have a CSS file called App.css that contains styles for the entire application.








