# Changing the background image

Let's see, as an example, the different ways you have to change the backgrounds image of the login page using CSS only.

{% hint style="info" %}
There is the equivalent of this guide using CSS-in-JS [here](/common-use-case-examples/changing-the-background-image-css-in-js.md).
{% endhint %}

First let's [download a background image](https://coolbackgrounds.io/) an put it in **src/login/assets/background.png**.

Then let's apply it as background:

{% code title="src/login/main.css" %}

```css
body.kcBodyClass {
  background: url(./assets/background.png) no-repeat center center fixed;
}
```

{% endcode %}

We import the StyleSheet:

{% tabs %}
{% tab title="React" %}

<pre class="language-tsx" data-title="src/login/KcPage.tsx"><code class="lang-tsx"><strong>import "./main.css";
</strong>// ...
</code></pre>

{% endtab %}

{% tab title="Angular" %}

<pre class="language-typescript" data-title="src/login/KcPage.ts"><code class="lang-typescript"><strong>import "./main.css";
</strong>import { getDefaultPageComponent, type KcPage } from '@keycloakify/angular/login';
// ...
</code></pre>

{% endtab %}

{% tab title="Svelte" %}

<pre class="language-html" data-title="src/login/KcPage.svelte"><code class="lang-html">&#x3C;script lang="ts">
<strong>  import "./main.css";
</strong>  ...
</code></pre>

{% endtab %}
{% endtabs %}

Result:

<figure><img src="/files/WmPcIpbZqi1AzhVW33zH" alt=""><figcaption><p>Custom background successfully applied</p></figcaption></figure>

<details>

<summary>Replacing the image without re-building the theme</summary>

If you want to be able to "hot swipe" the image, without rebuilding the theme you have to import the image from a different location.

Place the file into **/public/background.png**.

Then, in your CSS code import the image with an absolute path:

{% code title="src/login/main.css" %}

```css
body.kcBodyClass {
  background: url(/background.png) no-repeat center center fixed;
}
```

{% endcode %}

Now if you want to replace the image directly in Keycloak you'll be able to find it at:

**/opt/keycloak/themes/**[**\<name of your theme>**](/features/compiler-options/themename.md)**/login/resources/dist/background.png**

<img src="/files/UJnsC0zb7Td1ro2i4Wbi" alt="" data-size="original">

</details>

For a more advanced example, in the following video I show how to load different background for different page and how to create [theme variant](/features/theme-variants.md).

{% embed url="<https://youtu.be/Nkoz1iD-HOA?si=hBXt8rw72-Pvhhnr>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.keycloakify.dev/common-use-case-examples/changing-the-background-image.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
