There are several methods to style React components with CSS. This tutorial will focus on three common approaches:
To apply inline styles to an element, the value of the style attribute must be a JavaScript object.
Insert a JavaScript object containing the styling details.
const |
Note: In JSX, JavaScript expressions are enclosed in curly braces, and since objects also use curly braces, the styling in the example above is written within double curly braces {{}}. |
Since inline CSS is written as a JavaScript object, properties with hyphens, such as background-color, must be written in camelCase as backgroundColor.
Use backgroundColor instead of background-color.
const |
You can also create a separate object with the styling information and reference it in the style attribute.
Create a style object called myStyle.
const |