Course Content
React JSX
React JSX (JavaScript XML) is a syntax extension for JavaScript that allows you to write HTML-like code within JavaScript. JSX makes it easier to create React components and define their structure in a more readable and declarative way.
0/1
Components in React
In React.js, components are the building blocks of a React application. They allow you to break the UI into independent, reusable pieces and think about each piece in isolation. Here's an overview of components in React:
0/1
Props in React
Props (short for properties) are a way to pass data from a parent component to a child component in React. They are read-only and cannot be modified by the child component, ensuring a unidirectional data flow.
0/1
React Events
Just like HTML DOM events, React can perform actions based on user events.React has the same events as HTML: click, change, mouseover etc.
0/1
React Conditional Rendering
0/1
React Lists
0/1
React Forms
0/1
Styling React Using CSS
0/1
React Router
0/1
React Js
About Lesson

Styling React Using CSS:

There are many ways to style React with CSS, this tutorial will take a closer look at three common ways:

  • Inline styling
  • CSS stylesheets
  • CSS Modules

Inline styles are applied directly to elements using the style attribute. The style object follows JavaScript syntax (camelCase properties).

Example:

import React from "react";
JavaScript
function InlineStyle() {
  return <h2 style={{  color: "blue",fontSize: "24px",textAlign: "center" }}>This is an inline styled heading</h2>;
}
export default InlineStyle;

CSS Stylesheets (Global CSS):

You can write regular CSS styles in a separate .css file and import it into your React component.

App.css (Stylesheet):

CSS
.heading {
  color: green;
  font-size: 24px;
  text-align: center;
}

App.js:

JavaScript
import React from "react";
import "./App.css"; // Importing CSS fill
function StylesheetExample() {
  return <h2 className="heading">This is a styled heading using CSS file</h2>;
}
export default StylesheetExample;

CSS Modules allow component-specific styles to avoid conflicts. The styles are locally scoped to the component.

Button.module.css:

CSS
.button {
  background-color: purple;
  color: white;
  padding: 10px 20px;
  border: none;
  cursor: pointer;
}
.button:hover {
  background-color: darkviolet;
}

Button.js:

JavaScript
import React from "react";
import styles from "./Button.module.css"; // Importing CSS Module
function Button() {
  return <button className={styles.button}>Click Me</button>;
}
export default Button;