Using CSS in React JS Code – JSX

Use css attributes for HTML code in the React JS app code. Here is the sample code of css usage for styling the react app.

Instead of classname="heading" , className="heading" is used

React JS Code – CSS Usage

index.js

import React from "react";
import ReactDOM from "react-dom";

ReactDOM.render(
  <div>
    <h1 className="heading"
     contentEditable="true" 
     spellCheck="false">My Favourite  Foods</h1>
    <ul>
      <li>Bacon</li>
      <li>Jamon</li>
      <li>Noodles</li>
    </ul>
  </div>,
  document.getElementById("root")
);

style.css

.heading{
  color:red
}

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>JSX</title>
    <link rel="stylesheet" href="styles.css" />
  </head>

  <body>
    <div id="root"></div>
    <script src="../src/index.js" type="text/JSX"></script>
  </body>
</html>

About the Author: smartcoder

You might like

Leave a Reply

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