Categories
React Answers

How to Set Text Color in React?

Spread the love

Sometimes, we want to set text color in React.

In this article, we’ll look at how to set text color in React.

Set Text Color in React

To set text color in React, we can set the style prop to an object with the color property.

For instance, we write:

import React from "react";

export default function App() {
  return (
    <>
      <h1 style={{ color: "red" }}>Hello world</h1>
    </>
  );
}

to set the style prop of the h1 element to an object that has the color property set to 'red'.

Now we should see that the color of the text is red.

Conclusion

To set text color in React, we can set the style prop to an object with the color property.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *