EN
React - backgroundImage with inline style
1 points
In this article, we would like to show you how to set a background image with React inline styles.
There are two main methods for setting the background image:
xxxxxxxxxx
1
import background from "./img/background_image.png";
2
3
const App = () => {
4
return (
5
<div style={{ backgroundImage: `url(${background})` }}>
6
// some text inside...
7
</div>
8
);
9
}
10
11
export default App;
xxxxxxxxxx
1
const App = () => {
2
const backgroundURL = "https://images.pexels.com/photos/459653/pexels-photo-459653.jpeg";
3
return (
4
<div style={{ backgroundImage: `url(${backgroundURL})` }}>
5
// some text inside...
6
</div>
7
);
8
};
9
10
export default App