How to add full background image in react js?

Hi Friends πŸ‘‹,

Welcome To aHoisting!

To add full background image in react js, you can set background-image: url('./[email protected]'); in .full-background. It will add full background image in react js.

Today, I am going to show you, how to add full background image in react js.

Table of contents

  • Install and create a new React app.
  • Import react component.
  • Create a Component.

Let’s start with the first step.

Step 1: Install and create a new React app.

First you have to install the React project. You should use create-react-app command to create a new React project.

npx create-react-app my-app
cd my-app
npm start

Step 2: Import react component.

After installing, you have to import your React component. To do this, add the following line to the top of your component file.

import React from 'react';
import './App.css';

Step 3: Create a Component.

You can use className="full-background" to add full background image in react js.

<div className="full-background">
  {/* Your content here */}
</div>

Define the add full background image example.

The below code is an example of a React. You have to import './App.css' and set background-image: url('./[email protected]'); in .full-background to add full background image in react js.

App.js

import React from 'react';
import './App.css';

function App() {
  return (
    <div className="full-background">
      {/* Your content here */}
    </div>
  );
}

export default App;
.full-background {
  background-image: url('./[email protected]');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  width: 100vw;
  height: 100vh;
}

In the above code example, I have used the background-image: url('./[email protected]'); and add full background image in react js.

Check the output of the above code example.

React, full-background-image

All the best πŸ‘