githubEdit

image-landscapeChanging 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.

circle-info

There is the equivalent of this guide using CSS-in-JS here.

First let's download a background imagearrow-up-right an put it in src/login/assets/background.png.

Then let's apply it as background:

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

We import the StyleSheet:

src/login/KcPage.tsx
import "./main.css";
// ...

Result:

Custom background successfully applied
chevron-rightReplacing the image without re-building the themehashtag

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:

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>/login/resources/dist/background.png

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.

Last updated

Was this helpful?