Keycloakify
HomeGitHubStorybookAlternative to keycloak-js
v11
  • Documentation
  • Release Notes & Upgrade Instructions
  • FAQ
v11
  • Quick Start
  • CSS Customization
  • Testing your Theme
    • Outside of Keycloak
    • Inside of Keycloak
  • Deploying Your Theme
  • Integrating Keycloakify in your Codebase
    • Vite
    • Create-React-App / Webpack
    • yarn/npm/pnpm/bun Workspaces
    • Turborepo
    • Nx
    • Angular Workspace
  • Common Use Case Examples
    • Using a Component Library
    • Custom Fonts
    • Changing the background image
    • Adding your Logo
    • Using Tailwind
    • Dark Mode Persistence
  • Features
    • Internationalization and Translations
      • Basic principles
      • Previewing Your Pages in Different Languages
      • Adding New Translation Messages or Changing the Default Ones
      • Adding Support for Extra Languages
    • Theme Variants
    • Environment Variables
    • Styling a Custom Page Not Included in Base Keycloak
    • Integrating an Existing Theme into Your Keycloakify Project
    • Compiler Options
      • --project
      • keycloakVersionTargets
      • environmentVariables
      • themeName
      • startKeycloakOptions
      • themeVersion
      • accountThemeImplementation
      • postBuild
      • XDG_CACHE_HOME
      • kcContextExclusionsFtl
      • keycloakifyBuildDirPath
      • groupId
      • artifactId
      • Webpack specific options
        • projectBuildDirPath
        • staticDirPathInProjectBuildDirPath
        • publicDirPath
  • Page-Specific Guides
    • Registration Page
    • Terms and Conditions Page
  • Theme types
    • Differences Between Login Themes and Other Types of Themes
    • Account Theme
      • Single-Page
      • Multi-Page
    • Email Theme
    • Admin Theme
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. Common Use Case Examples

Changing the background image

Last updated 4 months ago

Was this helpful?

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

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

First let's 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";
// ...
src/login/KcPage.ts
import "./main.css";
import { getDefaultPageComponent, type KcPage } from '@keycloakify/angular/login';
// ...
src/login/KcPage.svelte
<script lang="ts">
  import "./main.css";
  ...

Result:

Replacing the image without re-building the theme

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:

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

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

/opt/keycloak/themes//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 .

<name of your theme>
theme variant
here
download a background image
Custom background successfully applied