# How to set image in page background in ionic 4?

**URL:** <https://forum.ionicframework.com/t/how-to-set-image-in-page-background-in-ionic-4/157728>\
**Category:** Ionic Framework\
**Created:** [February 27, 2019, 2:11pm UTC](https://forum.ionicframework.com/t/how-to-set-image-in-page-background-in-ionic-4/157728 "2019-02-27T14:11:03Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![gokujy](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/gokujy/32/117753_2.png) [@gokujy](https://forum.ionicframework.com/u/gokujy)\
**Post date:** [February 27, 2019, 2:11pm UTC](https://forum.ionicframework.com/t/how-to-set-image-in-page-background-in-ionic-4/157728/1 "2019-02-27T14:11:03Z")

</div>

Hello, I want set background image in my page, anyone know how to do?  
Please help if possible…!

---

<div class="post-metadata">

**Author:** ![ChrisGriiffith](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/chrisgriiffith/32/66576_2.png) [@ChrisGriiffith](https://forum.ionicframework.com/u/ChrisGriiffith)\
**Post date:** [February 27, 2019, 4:55pm UTC](https://forum.ionicframework.com/t/how-to-set-image-in-page-background-in-ionic-4/157728/2 "2019-02-27T16:55:05Z")

</div>

You can set that using the CSS in the global.scss file. Here is a sample

```auto
ion-content {
    --background: #fff url("assets/bg.jpg") no-repeat center center / cover;
}

```

---

<div class="post-metadata">

**Author:** ![gokujy](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/gokujy/32/117753_2.png) [@gokujy](https://forum.ionicframework.com/u/gokujy)\
**Post date:** [February 28, 2019, 5:32am UTC](https://forum.ionicframework.com/t/how-to-set-image-in-page-background-in-ionic-4/157728/3 "2019-02-28T05:32:27Z")

</div>

this way we can set for all pages, but i want show background image in only login page and when i put this code in login scss coming error…  
Error:

```auto
client:162 [WDS] Errors while compiling. Reload prevented.
errors @ client:162
onmessage @ socket.js:41
EventTarget.dispatchEvent @ sockjs.js:170
(anonymous) @ sockjs.js:887
SockJS._transportMessage @ sockjs.js:885
EventEmitter.emit @ sockjs.js:86
WebSocketTransport.ws.onmessage @ sockjs.js:2961
wrapFn @ zone.js:1332
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask @ zone.js:423
push../node_modules/zone.js/dist/zone.js.Zone.runTask @ zone.js:195
push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask @ zone.js:498
invokeTask @ zone.js:1744
globalZoneAwareCallback @ zone.js:1770
client:168 ./src/app/login/login.page.scss
Module Error (from ./node_modules/postcss-loader/src/index.js):
(Emitted value instead of an instance of Error) CssSyntaxError: E:\project\ZoroAndroid\src\app\login\login.page.scss:26:16: Can't resolve 'assets/imgs/login-bg.png' in 'E:\project\ZoroAndroid\src\app\login'

  24 | 
  25 | ion-content {
> 26 | --background: #fff url("assets/imgs/login-bg.png") no-repeat center center / cover;
     | ^
  27 | }

```

---

<div class="post-metadata">

**Author:** ![ChrisGriiffith](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/chrisgriiffith/32/66576_2.png) [@ChrisGriiffith](https://forum.ionicframework.com/u/ChrisGriiffith)\
**Post date:** [February 28, 2019, 3:13pm UTC](https://forum.ionicframework.com/t/how-to-set-image-in-page-background-in-ionic-4/157728/4 "2019-02-28T15:13:33Z")

</div>

When setting a background image at the individual page level, you will need to adjust the image path. For example:

```auto
ion-content {
    --background: #ccc url("../../assets/bg.jpg") no-repeat center center / cover;
}

```

I suspect that is the issue.

---

<div class="post-metadata">

**Author:** ![gokujy](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/gokujy/32/117753_2.png) [@gokujy](https://forum.ionicframework.com/u/gokujy)\
**Post date:** [February 28, 2019, 5:13pm UTC](https://forum.ionicframework.com/t/how-to-set-image-in-page-background-in-ionic-4/157728/5 "2019-02-28T17:13:27Z")

</div>

thank you, working perfect 🙂

---

<div class="post-metadata">

**Author:** ![Simran3798](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@Simran3798](https://forum.ionicframework.com/u/Simran3798)\
**Post date:** [February 16, 2020, 10:08am UTC](https://forum.ionicframework.com/t/how-to-set-image-in-page-background-in-ionic-4/157728/6 "2020-02-16T10:08:46Z")

</div>

Sir but then the contents are not visible properly.

 ![Untitled](https://global.discourse-cdn.com/ionicframework/original/3X/5/c/5ca103428c9b65605db4fef6ede5cfd2083ac11a.png)  
also the image is not uploading its full contnet.

---

<div class="post-metadata">

**Author:** ![ChrisGriiffith](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/chrisgriiffith/32/66576_2.png) [@ChrisGriiffith](https://forum.ionicframework.com/u/ChrisGriiffith)\
**Post date:** [February 18, 2020, 9:58pm UTC](https://forum.ionicframework.com/t/how-to-set-image-in-page-background-in-ionic-4/157728/7 "2020-02-18T21:58:57Z")

</div>

Depending on the design of your image, you may need to change the CSS properties as how the image will size and position itself.

---

<div class="post-metadata">

**Author:** ![Rahadur](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rahadur/32/113115_2.png) [@Rahadur](https://forum.ionicframework.com/u/Rahadur)\
**Post date:** [March 15, 2020, 4:28am UTC](https://forum.ionicframework.com/t/how-to-set-image-in-page-background-in-ionic-4/157728/8 "2020-03-15T04:28:12Z")

</div>

The best way is use tilde(~) operator before assets url.

```auto
ion-content {
   --background: #fff url("~/assets/img/bg.jpg") no-repeat center center / cover;
}

```

Or just

```auto
ion-content {
   --background: #fff url("/assets/img/bg.jpg") no-repeat center center / cover;
}

```

---

<div class="post-metadata">

**Author:** ![LuisEPerezP](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/luiseperezp/32/132849_2.png) [@LuisEPerezP](https://forum.ionicframework.com/u/LuisEPerezP)\
**Post date:** [July 28, 2020, 10:53pm UTC](https://forum.ionicframework.com/t/how-to-set-image-in-page-background-in-ionic-4/157728/9 "2020-07-28T22:53:17Z")

</div>

> [@ChrisGriiffith](#):
>
> `--background: #ccc url("../../assets/bg.jpg") no-repeat center center / cover;`

It could be set to top with:

```auto
--background: #ccc url("../../assets/bg.jpg") no-repeat top center / cover;

```

---

<div class="post-metadata">

**Author:** ![nbgroup](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/nbgroup/32/133289_2.png) [@nbgroup](https://forum.ionicframework.com/u/nbgroup)\
**Post date:** [July 29, 2020, 10:37am UTC](https://forum.ionicframework.com/t/how-to-set-image-in-page-background-in-ionic-4/157728/10 "2020-07-29T10:37:37Z")

</div>

Sir, i tried the way you told, but my content is not much visible in image.
