Inline Styling is the practice of defining styles directly within the JSX code, using JavaScript objects instead of external stylesheets or style blocks.
Double curly braces
With Inline styling, double curly braces {{ … }} are essentially used to interpolate the dynamic JavaScript object into the JSX code.
The property names in JavaScript object are camelCased to maintain alignment with JavaScript conventions. Creating an object with a key like "font-size" is not allowed in JavaScript hence it is camelCased as "fontSize."
const MyComponent = () => { return ( <div style={{ color: "blue", fontSize: "16px", border: "1px solid #ccc", }} > This is a component with inline styles. </div> ); };
Here’s how it works,
The outer pair of curly braces {} denotes that you are injecting a JavaScript expression into the JSX.
The inner pair of curly braces {dynamicStyle} represents the JavaScript object itself.
It is also possible to assign a JavaScript object containing styles to a variable and subsequently pass it to the style attribute in JSX, as shown below