2018-10-12 15:37:13 -04:00
---
title: Add Inline Styles in React
---
2019-07-24 00:59:27 -07:00
# Add Inline Styles in React
---
## Problem Explanation
2018-10-12 15:37:13 -04:00
You can declare a component style passing the object directly as a prop 'style'. Just remember that each property of the style object is camelcased. So properties like 'font-size' is declared 'fontSize' to be a valid javascript object property.
2019-07-24 00:59:27 -07:00
---
## Solutions
< details > < summary > Solution 1 (Click to Show/Hide)< / summary >
2018-10-12 15:37:13 -04:00
```jsx
2019-05-19 10:02:46 +06:00
const styles = {
color: 'purple',
fontSize: 40,
border: "2px solid purple",
};
2018-10-12 15:37:13 -04:00
class Colorful extends React.Component {
render() {
// change code below this line
return (
2019-05-19 10:02:46 +06:00
< div style = {styles} > Style Me!< / div >
2018-10-12 15:37:13 -04:00
);
// change code above this line
}
};
```
2019-07-24 00:59:27 -07:00
#### Relevant Links
2018-10-12 15:37:13 -04:00
[DOM Elements Style ](https://reactjs.org/docs/dom-elements.html#style )
2019-07-24 00:59:27 -07:00
< / details >