How to create inline styles in React
React lets you add CSS inline styles that are written as attributes and passed to elements. With inline styles, you have the option to combine CSS syntax with JSX code.
Note: Using the style attribute as your primary means of styling elements is generally not recommended.
This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.
Syntax
In React, inline styles are not specified as a string. Instead, they are specified with an object whose key is the style name, written in camelCase, and whose value is the style’s value, which is usually a string.
We can create inline styles in two ways:
- By creating a variable that stores style properties and then passing that variable to the element, like
style={styleVariable}. - By passing the styling directly, like
style={{height: '10%'}}.
Code
The following code creates inline CSS styles by directly passing the styling as an object:
This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved