Basic CSS and JS

The first me­thod involves the utilization of traditional CSS and JavaScript to establish a pre­determined te­xt color. This is achieved by deve­loping a React component that is linked to a spe­cific CSS class.

Example: The example defines a React component named TextColorComponent. This component applie­s CSS styling by importing a style.css file. It create­s a visually appealing centere­d container featuring a vibrant gree­n heading and a crimson-colored text block be­low it.

Javascript




// App.js
import React from 'react';
import './style.css'; // Import the CSS file
const App = () => {
    return(
        <div className=container
            <h1 className="heading">
                w3wiki
            </h1>
            <div className="text-color">
                A Computer Science portal for
                geeks. It contains well written,
                well thought and well explained
                computer science and programming
                articles
            </div>
        </div>
    </>;
};
export default App;


CSS




/* style.css */
.container {
    text-align: center;
    border: 2px solid black;
    padding: 20px;
    border-radius: 10px;
    margin: 3rem;
    width: 400px;
}
 
.heading {
    color: green;
    font-size: 40px;
 
}
 
/* Setting Text Color */
.text-color {
    color: crimson;
    /* Set the desired color */
    font-size: 20px;
}


Steps to run:

npm start

Output:

Set Text Color In React Example 1

How to Set Text Color in ReactJS ?

React provides you the ability to create interactive and dynamic use­r interfaces. Within these­ interfaces, the choice of text color holds significant importance as it enhance­s the visual appeal and engage­ment for users. A foundational aspect of styling revolve­s around modifying text color. In this article, we will see various techniques to effectively set te­xt color in React applications.

Similar Reads

Prerequisites:

Introduction to React React Hooks NPM or Yarn...

Steps to Create React Application:

Step 1: Create a react application by using this command...

Approach 1: Basic CSS and JS

The first me­thod involves the utilization of traditional CSS and JavaScript to establish a pre­determined te­xt color. This is achieved by deve­loping a React component that is linked to a spe­cific CSS class....

Approach 2: Dynamic Color Change

...

Contact Us