Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Adding your Logo

Practical example of how to import custom assets in ejected components.

NOTE: You can very well change the logo using only CSS without having to ejecting the template. There's a demo in this video.

Let's say you want to put the logo of your company on every pages of the theme.

First you'd eject the Template:

npx keycloakify eject-page # Select login -> Template.tsx

This will create a src/login/Template.tsx file in your project.

Let's use this placeholder for the demo: logo.png and save it in src/login/assets/logo.png.

Now we can use the asset in our component:

Result:

Optional: Updating the logo without re-building the theme

Some people want to be able to "hot swap" the asset in the Keycloak file system without having to re-build the theme and re-deploy it.

To ensure that the assets are located in a predictible location you would use the public/ directory.

Move the file to public/img/logo.png.

Then make an absolute import from your component:

It's important that you do not simply harcode src="/img/logo.png", or keycloakify won't be able to patch the URL for Keycloak. Use Vite's builtin import.meta.env.BASE_URL.

Doing this is a good practice in any Vite project (not specially Keycloakify) since it ensure the correctness of your URLs even if you customize the base parameter in the your vite.config.ts. Hard coding "/img/logo.png" only works when base is "/" (which is the default)

It's important that you do not simply harcode src="/img/logo.png", or keycloakify won't be able to patch the URL for Keycloak. Use Vite's builtin import.meta.env.BASE_URL.

Doing this is a good practice in any Vite project (not specially Keycloakify) since it ensure the correctness of your URLs even if you customize the "base" parameter in the your vite.config.ts. Writing "/img/logo.png" only works when base is "/" (which is the default)

It's important that you do not simply harcode src="/img/logo.png", or keycloakify won't be able to patch the URL for Keycloak. Use PUBLIC_URL instead.

NOTE: You can see PUBLIC_URL as an equivalent of process.env.PUBLIC_URL that will work inside and outside of Keycloak.

If you ever need to SSH into the Keycloak server and hot swap the image you can find it at

/opt/keycloak/themes/<name of your theme>/login/resources/dist/img/logo.png

Inspecting the Docker Keycloak docker image file system we can find the logo.png at the expected location.

Last updated

Was this helpful?