> For the complete documentation index, see [llms.txt](https://docs.keycloakify.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.keycloakify.dev/common-use-case-examples/changing-the-background-image.md).

# 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="https://2643300760-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4Ls5iTdfTS2xECgBfw90%2Fuploads%2Fgit-blob-71d7fd75c0c5775fe245dce9c3b6c7ecabfd8efc%2Fimage%20(124).png?alt=media" 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="https://2643300760-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4Ls5iTdfTS2xECgBfw90%2Fuploads%2Fgit-blob-df8d4a5ced17260f74f37087d4bbc82746731cb2%2Fimage%20(126).png?alt=media" 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
