docs

Theme Configuration and Management

You define which theme is used by your app either by using the theme configuration parameter or the sap/ui/core/Theming.setTheme method.


Using Custom Themes

To load an external custom theme, you can either declare it statically on the page or by setting the theme-root configuration parameter.


Theme Origin Allowlist

When configuring a theme with a themeRoot URL via the theme parameter, security restrictions apply. Absolute URLs to an origin other than the current page are cut off by default. The path segment will be resolved relative to the current page origin.

In order to allow other origins to be used via the URL parameter, the sap-allowed-theme-origins configuration option can be used:

<meta name="sap-allowed-theme-origins" content="https://example.com">

This allows you to load a theme from https://example.com, which is provided via the URL parameter:

https://myserver.com/sap/myapp/?sap-theme=my_theme@https://example.com/custom-themes/

Note:

sap-allowed-theme-origins can only be provided using bootstrap or the <meta> tag. Origins provided via configuration must contain the same protocol, host, and port as the origin provided in the theme parameter. Multiple allowed origins can be separated by a comma.

A general wildcard (*) can also be used to allow all origins. However, this should only be used in combination with additional security mechanisms, such as CSP style-src directives. Wildcards to allow sub-domains are not supported.


Listening to the Theming.applied Event

Whenever the theme is switched, an event is fired indicating that a theme switch has been triggered. If your application needs to take theming into consideration, attach an event handler, like this:

sap.ui.require([
    "sap/ui/core/Theming"
], (
    Theming
) => {
    "use strict";
     
    // Whenever the theme is switched, an event is fired,
    // indicating that a theme switch has been triggered.
    Theming.attachApplied((oEvent) => {
        // Note: The event callback has no longer a <this> context,
        // thus we use an arrow function here
 
        // Note: the Event object now has a different API than on the Core facade:
        // no more getParameters(), but simple properties like the Web API events.
        // Therefore, you can access the new "theme" like so:
        const sTheme = oEvent.theme;
    });
    ...
});

Note:

The handler of the applied event will be executed immediately once if all *.css files are loaded and there are no further requests pending for the theme.

After that, it will only be executed in case of new *.css files, which might happen for a complete theme change or the loading of additional libraries. Keep in mind that the onThemeChanged hook is not executed initially if the theme has already been applied.

For more information, see the API Reference.


Favicon Configuration

OpenUI5 provides flexible favicon management through the favicon configuration parameter and the Theming API.


Configuration Options

The favicon parameter supports three different values:


Basic Favicon Setup

Bootstrap Configuration:

<script
  id="sap-ui-bootstrap"
  src="/resources/sap-ui-core.js"
  data-sap-ui-favicon="true">
</script>

Programmatic Configuration:

JavaScript:

sap.ui.require(["sap/ui/core/Theming"], function(Theming) {
  Theming.setFavicon("assets/my-app-favicon.ico");
});

TypeScript:

import Theming from "sap/ui/core/Theming";

Theming.setFavicon("assets/my-app-favicon.ico");

Theme-Specific Favicon Behavior

If favicon is set to true:

For SAP standard themes:

For custom themes:


Security Considerations


Advanced Usage

Checking Current Favicon:

JavaScript:

sap.ui.require(["sap/ui/core/Theming"], function(Theming) {
  Theming.getFavicon().then(function(faviconPath) {
    console.log("Current favicon:", faviconPath);
  });
});

TypeScript:

import Theming from "sap/ui/core/Theming";

Theming.getFavicon().then((faviconPath: string) => {
  console.log("Current favicon:", faviconPath);
});

Conditional Favicon Setting:

JavaScript:

sap.ui.require(["sap/ui/core/Theming"], function(Theming) {
  var currentTheme = Theming.getTheme();
  if (currentTheme.includes("dark")) {
    Theming.setFavicon("assets/favicon-dark.ico");
  } else {
    Theming.setFavicon("assets/favicon-light.ico");
  }
});

TypeScript:

import Theming from "sap/ui/core/Theming";

const currentTheme = Theming.getTheme();
if (currentTheme.includes("dark")) {
  Theming.setFavicon("assets/favicon-dark.ico");
} else {
  Theming.setFavicon("assets/favicon-light.ico");
}

Advanced Theme Root Scenarios

Beyond basic theme root configuration, OpenUI5 supports complex scenarios for enterprise deployments and multi-service architectures.


Library-Specific Theme Roots

Configure different theme roots for specific libraries:

<script
  id="sap-ui-bootstrap"
  src="/resources/sap-ui-core.js"
  data-sap-ui-theme="myCustomTheme"
  data-sap-ui-theme-roots='{
    "myCustomTheme": {
      "": "https://general.theme.service/",
      "sap.ui.core": "https://core.theme.service/",
      "my.custom.lib": "https://custom.lib.service/"
    }
  }'>
</script>

In this configuration, the following applies:


Complex Multi-Service Setup

For large-scale deployments with multiple theming services:

JavaScript:

globalThis["sap-ui-config"] = {
  "theme": "myEnterpriseTheme",
  "theme-roots": {
    "myEnterpriseTheme": {
      "": "https://cdn.enterprise.com/ui5-themes/",
      "sap.ui.core": "https://core-themes.enterprise.com/",
      "sap.m": "https://mobile-themes.enterprise.com/",
      "company.custom": "https://custom-themes.enterprise.com/"
    },
    "myTestTheme": {
      "": "https://test-themes.enterprise.com/"
    }
  }
};

TypeScript:

(globalThis as any)["sap-ui-config"] = {
  "theme": "myEnterpriseTheme",
  "theme-roots": {
    "myEnterpriseTheme": {
      "": "https://cdn.enterprise.com/ui5-themes/",
      "sap.ui.core": "https://core-themes.enterprise.com/",
      "sap.m": "https://mobile-themes.enterprise.com/",
      "company.custom": "https://custom-themes.enterprise.com/"
    },
    "myTestTheme": {
      "": "https://test-themes.enterprise.com/"
    }
  }
};

Theme Root Inheritance and Fallbacks

Related Information

Available Configuration Options

API Reference: sap/ui/core/Theming.setTheme