Styling in React can be done in multiple ways. The two most common methods are:
style attribute with JavaScript objects.Inline styles in React are written as objects, where CSS properties are camelCased instead of kebab-case.
const headingStyle = {
color: '#004d40',
fontSize: '30px',
fontWeight: '700',
textAlign: 'center',
marginBottom: '20px'
};
function StyledHeading() {
return <h2 style={headingStyle}>Welcome to React Styling</h2>;
}
You can also add inline styles directly in JSX elements like this:
function Button() {
return (
<button
style={{
backgroundColor: '#00796b',
color: '#e0f2f1',
padding: '12px 24px',
border: 'none',
borderRadius: '8px',
cursor: 'pointer',
fontSize: '16px'
}}
>Click Me</button>
);
}
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!