How to put an image as background under multiple components in ReactJS with React Routing? Last Updated : 06 Jun, 2021 Comments Improve Suggest changes Like Article Like Report We can make a parent component and use that parent component to wrap the child component so that the parent component appears as an image overlay above the child component. Syntax: <div style={{ backgroundImage: `url(${'/background.jpg'})`}}> {props.children} </div> Creating React Application: Step 1: Create a React application using the following command: npx create-react-app foldername Step 2: After creating your project folder i.e. folder name, move to it using the following command: cd foldername Project Structure: It will look like the following. Filename-App.js: JavaScript import { React, Component } from 'react' import Parent from './Parent' class App extends Component { render() { return ( <Parent> <div> <h4 style={{ color: 'black', height: 200, width: 200, padding: 50 }}> This component has a background image </h4> </div> </Parent> ) } } export default App Filename-Parent.js: JavaScript import React ,{Fragment} from 'react' import { withRouter } from 'react-router-dom'; const Parent = (props) => { const URL = 'https://write.geeksforgeeks.org/static/media/Group%20210.08204759.svg' return ( <Fragment> <div style={{ backgroundImage: `url(${URL})`, backgroundRepeat:'no-repeat', backgroundColor: 'lightblue', }}> {props.children} </div> </Fragment> ) } export default withRouter(Parent); Â Step : To wrap this component on top of Routing Switch Component as Sample <Parent> Â Â Â Â Â Â <Switch> Â Â Â Â Â Â Â <Route path="/testpage" component={Test} /> Â Â Â Â Â Â Â <Route path="/testpage1" component={Test1} /> Â Â Â Â </Switch> </Parent> Step to Run Application: Run the application using the following command from the root directory of the project: Â npm startOutput: Now open your browser and go to http://localhost:3000/, you will see the following output: Â Â Comment More infoAdvertise with us Next Article How to put an image as background under multiple components in ReactJS with React Routing? K KapilChhipa Follow Improve Article Tags : Web Technologies ReactJS Similar Reads How To Set The Height And Width Of Background Image Inline Style In React? In React, while handling styles dynamically you might encounter setting a background image with specific dimensions using inline styles. While CSS stylesheets are generally preferred for styling, there are cases where inline styles make more sense, such as when you need to apply dynamic values or wo 3 min read How to set a Background Image With React Inline Styles ? Setting a background image with React inline style is a straightforward method of using the images as background to enhance the UI of the wen application.How to Set Background Image in React ?To set background image with react inline styles we will be using the style attribute. This style attribute 2 min read How to show user image along with input field in ReactJS? We can show the user image along with the input field in React JS. It is like adding an icon image inside the input field. This feature can also be seen on many website login screens. Material UI for React has this component available for us and it is very easy to integrate. We can use the InputAdor 3 min read How To Show Background Image In Tailwind CSS Using React Dynamic Url? Tailwind CSS is a utility-first framework that uses preset classes to greatly speed up styling. However, utility classes are insufficient when handling dynamic content such as background graphics. We'll demonstrate how to use Tailwind CSS for layout and styling in a React component while managing dy 3 min read How to set Background Image in react-native ? In this article, we will see how to set background Image in react-native. In our project, we will simply set a background image and show a text input on top of it. Setting background images requires using the ImageBackground component in React Native. You can style it further to adapt to different s 5 min read Like