There are multiple ways to style React with CSS: Inline Styling, CSS Stylesheets, and CSS Modules.
React Frontend Framework
React Tutorial
Advertisement
Google AdSense Slot (LEADERBOARD)
Automated High-CTR Ad Rail • Set Publisher ID in config/adsense.php
Styling
7 min read
•
Chapter 17 of 26
React CSS Styling
Style React applications using Inline styles with JavaScript objects, external CSS files, and scoped CSS Modules.
Example
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
</head>
<body style="font-family:sans-serif;padding:20px;">
<div id="root"></div>
<script type="text/babel">
function StyledComponent() {
const cardStyle = {
color: "white",
backgroundColor: "#0f172a",
padding: "20px",
fontFamily: "system-ui",
borderRadius: "14px",
maxWidth: "350px"
};
return (
<div style={cardStyle}>
<h3>React Inline Style Object</h3>
<p style={{color: "#38bdf8"}}>Properties use camelCase: backgroundColor, borderRadius.</p>
</div>
);
}
ReactDOM.createRoot(document.getElementById("root")).render(<StyledComponent />);
</script>
</body>
</html>
Try it Yourself >>
Opens live sandboxed code editor
Advertisement
Google AdSense Slot (IN-ARTICLE)
Automated High-CTR Ad Rail • Set Publisher ID in config/adsense.php
Community Q&A & Discussion
Verified
No questions yet. Be the first to start the discussion!